Question

I have an MVC structure, User.
It manages three types of users, users, clients and tenants; it's all done from the User.
What i need is a hidden parameter, that will be added to each route, that will tell the controller how to do it's job.

examples:

/clients/unverified/5 will be route to /users/unverified/client/5
and /tenants/unverified/5 will be route to /users/unverified/tenant/5

If you have a better idea of how it should be done, i will also appreciate it.

Was it helpful?

Solution

You can use same controller action as shown below:

Router::connect('/clients/unverified/:limit',
                array('controller' => 'users', 'action' => 'unverified',
                'client','5')
);
Router::connect('/tenants/unverified/:limit',
                array('controller' => 'users', 'action' => 'unverified',
               'tenants','5')
);
Router::connect('/whatever/unverified/:limit',
                array('controller' => 'users', 'action' => 'unverified',
               'whatever','5')
);

In users controller

 # $type would be clients/ tenants/ watever
 # $limit would be 5 
function unverified($type='user',$limit=5){

}

OTHER TIPS

Couple of options jump out at me:

1. Use Router::connect() in /app/config/routes.php:

This method should result in the ID being passed in without needing to specify it (as well as any other arguments).

Router::connect('/clients/unverified/*', array('controller' => 'users', 'action' => 'unverified', 'client'));
Router::connect('/tenants/unverified/*', array('controller' => 'users', 'action' => 'unverified', 'tenants'));

More info on routing in Cake 1.3.

2. Create clients and tenants controllers, unverified actions and simply redirect them to the users controller

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top