2014-10-08 83 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