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

时间:2016-02-27 17:56:54

标签: php phalcon

我跟随this official tutorial学习框架版 2.0.9

我有voteAction PollController以下代码应该在增加showAction后重定向或转发到number_votes,如下所示:

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则分别是

我尝试添加'controller' => 'poll'并将[]数组定义替换为array(),但没有。但是,当我为actionshowAction等密钥blah使用无效或未找到的操作名称时,会返回以下错误:

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}

1 个答案:

答案 0 :(得分:6)

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

如果您想重定向到其他网址,请使用:

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

例如,向前显示404页面非常有用。