如何从Typo3中的不同控制器操作访问相同的extbase视图



模型是在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视图。但我想把数据发送到init视图,在那里我重定向到结束。

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

或者你知道不同的解决方案吗?

我试了很多方法,但都不起作用。我要怎么做,把数据赋值给另一个视图?

$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

use $this->forward .

可能与$this->forward('init', 'xlfFiles');(未测试)

你可以在你的控制器中使用StandAloneView

/**
 * standaloneView
 *
 * @var TYPO3CMSFluidViewStandaloneView
 * @inject
 */
protected $standaloneView = NULL;
/**
 * TypoScript configuration
 *
 * @var array
 */
protected $ts = array();

你需要初始化它:

$this->ts = $this->configurationManager->getConfiguration(
TYPO3CMSExtbaseConfigurationConfigurationManager::CONFIGURATION_TYPE_FRAMEWORK, 
<your_ext_name_as_string>);
//set layout
$this->standaloneView->setLayoutRootPath(
TYPO3CMSCoreUtilityGeneralUtility::getFileAbsFileName(
$this->ts['view']['layoutRootPath']));
//set partials
$this->standaloneView->setPartialRootPath(
TYPO3CMSCoreUtilityGeneralUtility::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 = 
TYPO3CMSCoreUtilityGeneralUtility::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);

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

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

最新更新