2014-10-08 87 views
2

我有自己的擴展,有兩個動作控制器:listAction和showAction。
問題:我可以在同一頁面顯示兩項操作嗎?TYPO3 Extbase switchableControllerActions

在特定頁面我創建了一個插件插件記錄,使用我自己的插件在插件的後端配置的flexform中,我通過switchableControllerActions字段選擇了「list action」。列表操作包含與產品展示操作鏈接的產品列表。

那麼我想要什麼?

F.e. 我有頁面產品。網址爲example.com/products(這是我的名單行動)
而對於表演動作我想要的網址類似example.com/products/name-of-product

我已經發現了這個功能的擴展。這是gb_events。我注意到在插件的flexform的switchableControllerActions字段中有這樣的東西:

<switchableControllerActions> 
     <TCEforms> 
      <label>LLL:EXT:gb_events/Resources/Private/Language/locallang_db.xlf:flexform.default.switchableControllerActions</label> 
      <config> 
      <type>select</type> 
      <items type="array"> 
       <numIndex index="0" type="array"> 
       <numIndex index="0">LLL:EXT:gb_events/Resources/Private/Language/locallang_db.xlf:flexform.default.switchableControllerActions.upcoming</numIndex> 
       <numIndex index="1">Event->upcoming;Event->list;Event->calendar;Event->show;Event->export</numIndex> 
       </numIndex> 
       <numIndex index="1" type="array"> 
       <numIndex index="0">LLL:EXT:gb_events/Resources/Private/Language/locallang_db.xlf:flexform.default.switchableControllerActions.list</numIndex> 
       <numIndex index="1">Event->list;Event->upcoming;Event->calendar;Event->show;Event->export</numIndex> 
       </numIndex> 
       <numIndex index="2" type="array"> 
       <numIndex index="0">LLL:EXT:gb_events/Resources/Private/Language/locallang_db.xlf:flexform.default.switchableControllerActions.calendar</numIndex> 
       <numIndex index="1">Event->calendar;Event->upcoming;Event->list;Event->show;Event->export</numIndex> 
       </numIndex> 
       <numIndex index="3" type="array"> 
       <numIndex index="0">LLL:EXT:gb_events/Resources/Private/Language/locallang_db.xlf:flexform.default.switchableControllerActions.details</numIndex> 
       <numIndex index="1">Event->show;Event->list;Event->upcoming;Event->calendar;Event->export</numIndex> 
       </numIndex> 
      </items> 
      <maxitems>1</maxitems> 
      <size>1</size> 
      </config> 
      <onChange>reload</onChange> 
     </TCEforms> 
     </switchableControllerActions> 

我已經更新了我的flexform配置。但它仍然不起作用。當我點擊鏈接show action後,我有相同的列表視圖。

在此先感謝。我會感謝任何幫助。

回答

0

結構上更爲合理的方法是在控制器內部保留這種邏輯。

讓你的showAction成爲一個默認的人並檢查其初始化中的參數。如果沒有給出產品,或者指定的產品無法裝入,則轉發到列表操作。

/** 
* initialize action show 
* @return void 
*/ 
public function initializeShowAction() { 
    if($this->request->hasArgument('product')){ 
     if($product=$this->stadtRepository->findByUid( 
      intval($this->request->getArgument('product')) 
     )){ 
      $this->request->setArgument('product',$product); 
      return; 
     } 
    } 
    $this->forward('list'); 
} 
+1

感謝您的回答。這是一個好主意,就像你在這裏描述的那樣:) 如果我有足夠的聲望,我會投票。 – andr 2016-08-11 21:10:38

2

請確保您有兩個,列表和細節動作在你switchableControllerActions像這樣:

<numIndex index="0" type="array"> 
      <numIndex index="0">LLL:EXT:gb_events/Resources/Private/Language/locallang_db.xlf:flexform.default.switchableControllerActions.upcoming</numIndex> 
      <numIndex index="1">Event->list;Event->calendar;Event->show</numIndex> 
      </numIndex> 

然後在您的TypoScript模板中使用的條件基於一個詳細的UID設置控制器/行動:

[globalVar = GP:tx_myext_plugin|showUid > 0] 
config.defaultGetVars { 
    tx_myext_plugin.action = show 
} 
[global] 

要獲得另一個控制器參數關在RealUrl URL中使用這樣的事情:

array(
    'GETvar' => 'tx_extkey_plugin[action]', 
    'noMatch' => 'bypass' 
), 

在這篇德語文章中,您可以找到關於此技巧的更多信息here