0
votes

I am a bit in dead end trying to mane my routes in CakePHP. I read almost every article in the www and some of them close to what i need but combining with other dont work as expected. Also tried some router lib-s, but the same

Here is what I need:

Both language parameter in the url and a slug of the pages. So:

for the frontend

the directory '/' should lead to the default language, controller => pages , slug => home

/:lang - the same as above but with selected language

/:slug - controller => pages , action => index and to pass the :slug parameter, with default language

/:lang/:slug - the same as above with set lang parameter

/:controller/:slug -

/:lang/:controller/:slug - the same as above with set lang parameter

  • I dont need any action-s in those links

for the admin panel

/admin - 'controller' => 'settings', 'action' => 'index'

/admin/:controller/:action/ .... this one is the default

  • no need for language parameter in the admin url, but actions exists, except the index action

Also how should I create the links inside the view, so the routers to be working as the should?

1

1 Answers

1
votes
    Router::connect("/admin", array('action' => 'index', 'controller' => 'settings', 'prefix' => 'admin', 'admin' => true));
    Router::connect("/admin/:controller", array('action' => 'index', 'prefix' => 'admin', 'admin' => true));
    Router::connect("/admin/:controller/:action/*", array('prefix' => 'admin', 'admin' => true));

    Router::connect("/:language/*", array('action' => 'home', 'controller' => 'pages'));
    Router::connect("/:language/:controller", array('action' => 'index'));
    Router::connect("/:language/:controller/*");

You can copy past the second set of routes, but changing :language to slug, you should put it in an if and validate the language given, if it doesn't validate then load the slug routes.