【问题标题】:Phalcon PHP dispatcher forward does not workPhalcon PHP调度程序转发不起作用
【发布时间】:2016-02-27 17:56:53
【问题描述】:

我正在关注this official tutorial学习框架版本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 是投票分别

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

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}

【问题讨论】:

    标签: phalcon php phalcon


    【解决方案1】:

    转发不会进行 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"
    ));
    

    例如 Forward 对显示 404 页面很有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-14
      • 1970-01-01
      • 1970-01-01
      • 2014-12-18
      • 2020-02-14
      • 2017-05-14
      • 2015-07-31
      • 2020-12-21
      相关资源
      最近更新 更多