将参数传递给不同的控制器或替代品

Passing arguments to a different controller or alternatives

在我的 extbase 扩展中,我有一个约会模型,用户可以写下关于约会如何的反馈。
所以我创建了一个不同领域的反馈模型。
现在当用户点击 "Create Feedback" 按钮时我应该实现什么?
到目前为止我得到了这个,但它不起作用:

<f:link.action action="edit" controller="Feedback" arguments="{appointment:appointment}">

我收到错误:

Argument 1 passed to ...Controller\FeedbackController::newAction() must be an instance of ...\Model\Appointment, none given

反馈控制器:

     /**
     * action new
     * @param ...\Domain\Model\Appointment $appointment
     * @return void
     */
    public function newAction(...\Domain\Model\Appointment $appointment) {
        $this->view->assign('appointment', $appointment);
    }

为什么会出现此错误? (约会对象肯定有,我调试了)
我认为这一定与从 AppointmentController 到 FeedbackController 的切换有关。

实现这个的最佳方法是什么?

检查 ext_localconf.php 和 post 中的 plugin-controller-action 数组。可能有问题。

如果您使用不同的插件,您的 link 代中需要 pluginName 参数。

<f:link.action action="edit" controller="Feedback" pluginName="your_plugin" arguments="{appointment:appointment}">

生成 link 时,TYPO3 将参数的 "namespace" 添加到 link 的前面,如下所示:tx_myplugin[action]=new。确保 pluginName 与您在 ext_localconf.php 中定义的相同。在这种情况下,插件名称将是 your_plugin.

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'Vendor.' . $_EXTKEY,
    'your_plugin',
    array(
        'Feedback' => 'new',
    ),
    // non-cacheable actions
    array(
        'Feedback' => '',
    )
);

如果您遇到此错误:

Argument 1 passed to ...Controller\FeedbackController::newAction() must be an instance of ...\Model\Appointment, none given

这是因为您给控制器一个 NULL 对象,而您的控制器不允许这样做。

为避免此错误,您可以在控制器中允许 NULL 对象:

   /**
     * action new
     * @param ...\Domain\Model\Appointment $appointment
     * @return void
     */
    public function newAction(...\Domain\Model\Appointment $appointment=NULL) {
        $this->view->assign('appointment', $appointment);
    }

这很奇怪,因为在你的 link 中,你调用了一个动作 'edit' 并且你在 'newAction' 控制器而不是 'editAction' 控制器中有一个错误,你应该您的插件允许的 'edit' 操作(可缓存或不可缓存):

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'Vendor.' . $_EXTKEY,
    'your_plugin',
    array(
        'Feedback' => 'edit',
    ),
    // non-cacheable actions
    array(
        'Feedback' => 'edit',
    )
);

如 Natalia 所写,如果您要调用的操作属于另一个插件,请添加插件名称。

<f:link.action action="edit" controller="Feedback" pluginName="your_plugin" arguments="{appointment:appointment}">

弗洛里安