Phalcon PHP 调度程序转发不起作用

Phalcon PHP dispatcher forward does not work

我正在关注 this official tutorial to learn 框架版本 2.0.9

我有一个 voteActionPollController 以下代码应该在递增 number_votes 后重定向或转发到 showAction,如下所示:

public function voteAction($optionId)
{
    $option = PollOptions::findFirstById($optionId);
    $option->number_votes++;
    $option->save();
    return $this->dispatcher->forward([                
        'action' => 'show',
        'params' => [$option->poll_id]
    ]);
}

然而,投票后我得到的是 poll/vote/xx 而不是 poll/show/yy 其中 xx 是选项 ID,yy 是民意调查分别是 。 =26=]

我尝试添加 'controller' => 'poll' 并用 array() 替换 [] 数组定义,但没有任何效果。但是,当我为键 action 使用无效或未找到的操作名称时,例如 showActionblah 它 returns 出现以下错误:

Action 'showAcyoimn' was not found on handler 'poll'
#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('Action 'showAcy...', 5)
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 C:\xampp\htdocs\blog\public\index.php(29): Phalcon\Mvc\Application->handle()
#3 {main}

Forward 不进行 HTTP 重定向。更多信息在这里:https://docs.phalconphp.com/en/latest/reference/dispatching.html#forwarding-to-other-actions

如果您想重定向到其他 url 使用:

return $this->response->redirect(array(
  "controller" => "index",
  "action" => "actionName",
  "params" => "paramValues"
));

例如转发对于显示 404 页面很有用。