lithium icon indicating copy to clipboard operation
lithium copied to clipboard

Router::match skip persistent parameters

Open tefra opened this issue 13 years ago • 4 comments

It would be great if you could skip all persistent parameters all together instead of trying to set one by one as null, something like a reset flag you could pass in the options list which would pass to the router _prepareParams method, https://gist.github.com/3884585

tefra avatar Oct 13 '12 13:10 tefra

What would be the use case for this?

nateabele avatar Oct 19 '12 01:10 nateabele

Resolve conflicts between different routes with their own persistent params.

Example: Administrator panel with it's route

        Router::connect('admin/{:library}/{:controller}/{:action}/{:id}',
            array('admin' => true, 'library' => 'core', 'controller' => 'dashboard', 'action' => 'index', 'id' => null),
            array('persist' => array('admin', 'library', 'controller')));

And you want to link to something to the front-end, let's say a page route

        Router::connect('/article/{:slug:[\w\-\%]+}',
            array('library' => 'pages', 'controller' => 'page', 'action' => 'view', 'slug' => null),
            array('persist' => array('library', 'controller')));

You would have to set the admin param to null to make it work and that's ok.

$this->url(array('library' => 'pages',  'controller' => 'page', 'action' => 'view', 'admin' => null, 'slug' => $item->slug))

But imagine having a system like a cms/cmf where you could install libraries from various sources, it's impossible to resolve all persistent parameters conflicts. Let's say you have a contact-us plugin and you want to display a link in the header of all pages, the url would have to be hard-written because you don't know what conflicts may come up. That's where the reset flag comes in handy.

$this->url(array('library' => 'contact',  'controller' => 'form', 'action' => 'view'), array('reset' => true));

tefra avatar Oct 19 '12 10:10 tefra

i'd agree - i had that use-case several times and find it tiring to set all these parameters to null

d1rk avatar Oct 19 '12 10:10 d1rk

Got it, thanks for the feedback, guys.

nateabele avatar Oct 19 '12 13:10 nateabele