Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\Yaf\Route\Regex路由不到 #67

Closed
dev2geek opened this issue Nov 21, 2013 · 3 comments
Closed

\Yaf\Route\Regex路由不到 #67

dev2geek opened this issue Nov 21, 2013 · 3 comments

Comments

@dev2geek
Copy link

设置了一个Regex路由,girl/([\d]+),但是路由不到,最后都到了404. (前面两个路由都work)

public function _initRoute(\Yaf\Dispatcher $dispatcher) {
        //在这里注册自己的路由协议,默认使用简单路由
        $router = \Yaf\Dispatcher::getInstance()->getRouter();

        $route_0 = new \Yaf\Route\Rewrite(
            '*',
            array(
                'controller' => 'index',
                'action' => 'notfound')
        );

        $route_1 = new \Yaf\Route\Rewrite(
            'article/:id',
                array(
                    'controller' => 'index',
                    'action' => 'echo')
        );

        $route_2 = new \Yaf\Route\Regex(
            'girl/([\d]+)',
            array(
                'controller' => 'girl',
                'action' => 'number'
            ),
            array(
                1 => 'id'
            )
        );

        $router->addRoute('notfound', $route_0);
        $router->addRoute('article', $route_1);
        $router->addRoute('girl', $route_2);
    }
@laruence
Copy link
Owner

Regex要写完全的正则表达式 '#girl/([\d]+)#'

@dev2geek
Copy link
Author

Bingo,明白了,感谢~

@redybai
Copy link

redybai commented Apr 25, 2014

设置路由:
public function _initRoute(Yaf_Dispatcher $dispatcher) {
$router = Yaf_Dispatcher::getInstance()->getRouter();
$route = new Yaf_Route_Regex (
'testRoute/([a-zA-Z_0-9]+)',
array (
"controller" => "testRoute",
"action" => "index"
),
array()
) ;
$router->addRoute('testRoute', $route);
var_dump($router);
}

访问链接:http://myyaf.com/testRoute/index
浏览器上输出 路由信息:
object(Yaf_Router)#5 (2) {
["_routes":protected]=>
array(2) {
["_default"]=>
object(Yaf_Route_Static)#6 (0) {
}
["testRoute"]=>
object(Yaf_Route_Regex)#10 (4) {
["_route":protected]=>
string(25) "testRoute/([a-zA-Z_0-9]+)"
["_default":protected]=>
array(2) {
["controller"]=>
string(9) "testRoute"
["action"]=>
string(5) "index"
}
["_maps":protected]=>
array(0) {
}
["_verify":protected]=>
NULL
}
}
["_current":protected]=>
NULL
}

_current为NULL
也的确是没转向指定的controler。
对应的testRoute控制器是这么写的:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants