routing - CakePHP - How to make routes with custom parameters? -


my cake url this:

$token = '9kjhf8k104zx43';  $url = array(     'controller' => 'users',     'action' => 'password_reset',     'prefix' => 'admin',     'admin' => true,     $token ) 

i route prettier url like:

/admin/password-reset/9kjhf8k104zx43 

however, token @ end optional, in event doesn't provide token still routed to:

/admin/password-reset 

so can catch case , redirect page or display message.

i've read book on routing lot , still don't feel explains complex cases in way understand, don't know go this. like:

router::connect('/admin/password-reset/:token', array('controller' => 'users', 'action' => 'password_reset', 'prefix' => 'admin', 'admin' => true)); 

i don't know how optionally catch token , pass url.

you'll want use named parameters. example 1 of projects

router::connect('/:type/:slug',          array('controller' => 'catalogs', 'action' => 'view'),          array(             'type' => '(type|compare)', // regex match correct tokens             'slug' => '[a-z0-9-]+', // regex again ensure valid slug or 404             'pass' => array(                 'slug', // want pass through slug controller             )         )); 

then, in view can make link pass slug through.

echo $this->html->link('my link', array('controller' => 'catalogs', 'action' => 'view', 'type' => $catalog['catalogtype']['slug'], 'slug' => $catalog['catalog']['slug'])); 

my controller action looks this,

public function view($slug) {     // etc } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -