我跟随this official tutorial学习phalcon框架版 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()
,但没有。但是,当我为action
或showAction
等密钥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}
答案 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页面非常有用。