2014-01-15 28 views
2

在TYPO3 6.1.7上使用擴展構建器構建的extbase擴展中,我沒有通過Typoscript設置任何storagePid。如何使extbase擴展從插件識別存儲頁面?

但我已經在插件設置「記錄存儲頁面」:

enter image description here

我希望它會現在只能從這個頁面提取記錄。 但它不,它只是返回該表中的所有項目。

如何讓擴展程序識別插件的設置? 或者(如果它應該可以做到這一點),我怎麼知道它爲什麼不這樣做?

回答

7

下面的代碼添加到您的資料庫

namespace <Vendor>\<Extkey>\Domain\Repository; 

class ExampleRepository extends \TYPO3\CMS\Extbase\Persistence\Repository { 

    // Example for repository wide settings 
    public function initializeObject() { 
     /** @var $defaultQuerySettings \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings */ 
     $defaultQuerySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings'); 
     // add the pid constraint 
     $defaultQuerySettings->setRespectStoragePage(TRUE); 
} 

    // Example for a function setup changing query settings 
    public function findSomething() { 
     $query = $this->createQuery(); 
     // add the pid constraint 
     $query->getQuerySettings()->setRespectStoragePage(TRUE); 
     // the same functions as shown in initializeObject can be applied. 
     return $query->execute(); 
    } 
} 

你會發現更多的信息在本頁面 http://forge.typo3.org/projects/typo3v4-mvc/wiki/Default_Orderings_and_Query_Settings_in_Repository

+0

感謝Stefano!我想我的頁面樹中有一些混亂的設置,重新創建整個頁面,即使沒有setRespectStoragePage(TRUE)。我認爲我的理解正確,如果不是,請更正我的意見:存儲頁面默認應該受到尊重;你的代碼只是爲了執行它? – Urs

+1

是的,你可以在設置類(typo3/sysext/extbase/Classes/Persistence/Generic/Typo3QuerySettings.php)中看到,這應該是默認設置。不知怎麼的(一些擴展改變它),你需要爲你的倉庫明確地設置它。 'protected $ respectStoragePage = TRUE;' –

1

其實我修改了我的MVC控制器來實現取決於實際的頁面上的記錄過濾(storagePid == page.id)..看起來像這樣:

use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; 

class MyMVCController extends ActionController { 
protected function initializeAction() { 
    parent::initializeAction(); 
    //fallback to current pid if no storagePid is defined 
    $configuration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); 
    if (empty($configuration['persistence']['storagePid'])) { 
     $currentPid['persistence']['storagePid'] = GeneralUtility::_GP('id'); 
     $this->configurationManager->setConfiguration(array_merge($configuration, $currentPid)); 
    } 
[..] 

我用的解決方案並修改了storagePid的值導致我開發了一個後端模塊。 他tscript例如didnt工作對我來說.. 也是article by Thomas Deuling是爲主題的有趣..

,但我仍然沒有得到整個連接到我的心..想回去的symfony的xD

編輯:爲修改回購查詢也這篇文章看起來很有趣: https://forge.typo3.org/projects/typo3v4-mvc/wiki/Default_Orderings_and_Query_Settings_in_Repository

7

我做了很多研究,當我的擴展的前端插件(TYPO3 7.6.4)拒絕使用插件的'頁'字段(「記錄存儲頁面「),所以我想分享我的發現:

我的擴展名是 'tx_dhsnews',我的插件的名稱是 '信息框'

  1. setRespectStoragePage必須設置爲true(默認):$查詢 - > setRespectStoragePage(TRUE)

  2. 在typoscript-setup,插件專用的存儲空間 plugin.tx_dhsnews_infobox.persistence.storagePid 絕對不能出現!不是帶有空值的事件!否則'pages'字段將不被尊重!

就這樣。 Extensions Builder只是創建了一個typoscript-setup,將特定插件'infobox'的storagePid設置爲無。這導致插件不尊重'網頁'字段。

在擴展級別上設置storagePid是沒有問題的(例如'tx_dhsnews..persistence.storagePid'),該值將與'pages'(「記錄存儲頁面」)中給出的值合併。 ,但是儘快插件特定的tx_ [extension] _ [plugin] .persistence。storagePid存在於typoscript中,它將否決所有其他的東西!

希望這會幫助別人節省一些時間+神經

+0

是的,刪除'persistence.storagePid'這行確實節省了我一些神經,感謝:D –