【问题标题】:How access the same extbase view from different controller actions in Typo3如何从 Typo3 中的不同控制器操作访问相同的 extbase 视图
【发布时间】:2015-09-20 22:02:05
【问题描述】:

模型是,在 extbase 上开发 Typo3 BE 扩展。

我只想使用一个带有选择框、文本区域的视图... 但是如果我调用一个特定的动作,Typo3 期望一个具有相同名称的视图。

public function xyzAction(array $extName = NULL) {
        error_log($extName['extList'][1]."-xlfAction-".$extName['search']);
        $xlfFiles = array();
        $xlfFiles[] = "Test2";
        $this->view->assign('xlfFiles', $xlfFiles);
        $this->redirect('init');
    }

$this->view->assign(...) 尝试将数据发送到 xyz 视图。但我想将数据发送到初始化视图,最后重定向到那里。

我需要的是一个视图对象(替换 $view),它将数据分配给 init 视图而不是 xyz 视图。

或者您知道其他解决方案吗?

我尝试了很多东西,但没有任何效果。 那么我该怎么做才能将数据分配给不同的视图呢?

【问题讨论】:

    标签: typo3


    【解决方案1】:
    $arguments = [
      'arg1'  =>  $arg1,
      'arg2'  =>  $arg2
    ];
    $this->redirectWithUriBuilder('actionName', 'controllerName', '', $arguments);
    

    或者你也可以使用$this->redirect()

    https://typo3.org/api/typo3cms/class_t_y_p_o3_1_1_c_m_s_1_1_extbase_1_1_mvc_1_1_controller_1_1_abstract_controller.html#afb75136221ebb5f62df87bb0be4a5108

    【讨论】:

      【解决方案2】:

      使用$this->forward

      也许$this->forward('init', 'xlfFiles');(未测试)

      【讨论】:

        【解决方案3】:

        您可以在 Controller 中使用 StandAloneView。

        /**
         * standaloneView
         *
         * @var \TYPO3\CMS\Fluid\View\StandaloneView
         * @inject
         */
        protected $standaloneView = NULL;
        
        /**
         * TypoScript configuration
         *
         * @var array
         */
        protected $ts = array();
        

        你需要初始化它:

        $this->ts = $this->configurationManager->getConfiguration(
        \TYPO3\CMS\Extbase\Configuration\ConfigurationManager::CONFIGURATION_TYPE_FRAMEWORK, 
        <your_ext_name_as_string>);
        
        //set layout
        $this->standaloneView->setLayoutRootPath(
        \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(
        $this->ts['view']['layoutRootPath']));
        
        //set partials
        $this->standaloneView->setPartialRootPath(
        \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(
        $this->ts['view']['partialRootPath']));
        
        //Set extension and plugin name
        $extensionName = $this->request->getControllerExtensionName();
        $pluginName = $this->request->getPluginName();
        $this->standaloneView->getRequest()->setControllerExtensionName($extensionName);
        $this->standaloneView->getRequest()->setPluginName($pluginName);
        

        最后,您可以“更改”您的视图并设置不同的模板名称以处理其他视图。

        $this->view = $this->standaloneView;
        
        //Generate a new fileName
        $newTemplateFileName = 
        \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(
        $this->ts['view']['templateRootPath'] . 
        (substr($this->ts['view']['templateRootPath'], -1) == '/' ? '' : '/') 
        . '<Your_Folder>/<Your_File>.html');
        
        //assign the new template file to the view.
        $this->view->setTemplatePathAndFilename($newTemplateFileName);
        
        //at this point you can assign values to your selected template
        $this->view->assign('your_variable', $variable);
        

        【讨论】:

        • 终于找到了如下解决方案:
        【解决方案4】:

        最终我找到了以下解决方案:

        public function xyzAction(array $extName = NULL) {
            $xlfFiles = array();
            $xlfFiles[] = "Test2";
            $this->redirect('init', NULL, NULL, array('xlfFiles' => $xlfFiles));
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多