phalcon: 项目地址/P(.*) 与 路由
有一个项目地址:因客户渠道不同,带的参数也不相同。当时想到的是伪静态规则,但是发现自己没有那么强大。该走phalcon路由规则,地址如下:
www.xxx.com/Pbaidu
www.xxx.com/Psohu
www.xxx.com/Psansung
接受P(.*),P后面的数据为参数,获取后cookie缓存/session缓存,那么路由规则:
$di->set('router', function () {
$router = new Router();
$router->add("/P(.*)", array(
'controller' => 'index',
'action' => 'index',
'code' => 1
));
return $router;
});
那么获取参数,又是一头雾水,后来经过孜孜不倦的测试,获取的参数的方法如下:
var_dump($this->dispatcher->getParam('code'));
var_dump( $this->getParam('code') );
var_dump($_GET);exit;
最终:
$this->dispatcher->getParam('code');
能获取数据
记录一下。