我正在按照这个官方教程学习 phalcon 框架版本 2.0.9。
我voteAction
以下代码应该在增量number_votes
后重定向或转发到showAction
PollController
,如下所示:
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}
Forward 不会进行 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 页面很有用。