我正在按照这个官方教程学习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]
]);
}
Run Code Online (Sandbox Code Playgroud)
但是,投票后我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}
Run Code Online (Sandbox Code Playgroud)
转发不会使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"
));
Run Code Online (Sandbox Code Playgroud)
例如,向前显示404页面非常有用.