【问题标题】:TYPO3 Extbase switchableControllerActionsTYPO3 Extbase switchableControllerActions
【发布时间】:2014-10-08 19:03:01
【问题描述】:

我有自己的扩展,它有两个动作的控制器:listAction 和 showAction。
问题:我可以在同一页面上显示两个操作吗?

在特定页面上,我使用自己的插件创建了一个插入插件记录,在插件后端配置的 flexform 中,我通过 switchableControllerActions 字段选择了“列表操作”。列表操作包含产品列表,其中包含指向产品展示操作的链接。

那我想要什么?

F.e. 我有页面产品。网址是 example.com/products(这是我的列表操作)
对于显示操作,我想要 example.com/products/name-of-product

之类的 URL

我找到了具有此功能的扩展程序。这是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 配置。但它仍然不起作用。当我单击带有显示操作的链接后,我有相同的列表视图。

提前致谢。我将不胜感激。

【问题讨论】:

    标签: typo3 fluid extbase


    【解决方案1】:

    确保您同时拥有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中找到更多关于这个技巧的信息

    【讨论】:

      【解决方案2】:

      结构上更合理的方法是将这种逻辑保留在控制器中。

      将您的 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');
      }
      

      【讨论】:

      • 感谢您的回答。按照您在此处的描述这样做是个好主意 :) 如果我有足够的声誉,我会投票。
      猜你喜欢
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      • 2013-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多