【问题标题】:Phalcon: recive action parametrs with a question mark OR how to get variables from GET methodPhalcon:使用问号接收动作参数或如何从 GET 方法获取变量
【发布时间】:2013-01-25 08:00:39
【问题描述】:

我必须使用 http GET 方法从另一台服务器(令牌)接收信息。 我可以在我知道的时候更改 URL,所以我想我可以尝试让 GET 成为这样的操作中的参数:

start/tokenize/token?code=doekoedjorcfoehof

事实证明,在“?”之后的所有内容被忽略。 我还尝试定义路线:

$di->getRouter()->add("/tokenize?code={code}", "Start::tokenize");

所以这也被忽略了......

我认为'?与apache mod_rewrite有关,是否可以使用特殊的mod_rewrite规则检索GET?

【问题讨论】:

    标签: php apache mod-rewrite routes phalcon


    【解决方案1】:

    Router 组件无法从查询字符串中进行路由,它只能解析路由 uri:

    start/tokenize/token?code=doekoedjorcfoehof
    

    该 URL 的路由如下:

    $di['router'] = function() {
    
        $router = new Phalcon\Mvc\Router(false);
    
        $router->add('/start/tokenize/token', array(
            'controller' => 'tokenize',
            'action' => 'parse'
        ));
    
        return $router;
    };
    

    在您的控制器中:

    <?php
    
    class TokenizeController extends Phalcon\Mvc\Controller
    {
        public function parseAction()
        {
            $code = $this->request->getQuery('code');
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-07-08
      • 2021-10-25
      • 2011-01-20
      • 1970-01-01
      • 2011-12-09
      • 2010-12-29
      • 2020-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多