开发者

cakePHP router, route isn't working

I have this route:

Router::connect(
    '/:controller/*',
    array('controller'=>'con3'),
    array('controller'=>'con1|con2')
            );

I am trying to direct every call to

/con1/x1/x2

to

/con3/x1/x2

and

/con2/y1/y2

t开发者_开发技巧o

/con3/y1/y2

it is not working, why ?


If you require to route /con3/ to /con1/ and/or /con2/ based on your own constraints what you require is a Custom Route class. For this there is no better place than Mark Story's tutorial on custom Route classes.

Otherwise, you could of course just extend your controllers (and leave the body empty) like this:

<?php
class Con3Controller extends Con1Controller{
    // maybe add model here if you don't have
    // var $uses in Con1Controller
    // otherwise, extend is just fine
}
?>

In this case you don't need to mess with connecting routes like you are right now. Object inheritance will take care of your "aliasing" for you.


Have you considered something like:

Router::connect( '/con1/:action/*', array( 'controller' => 'con3' ) );
Router::connect( '/con2/:action/*', array( 'controller' => 'con3' ) );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜