Note that there are some explanatory texts on larger screens.

plurals
  1. PORouting all but certain parameters in CakePHP
    text
    copied!<p>I'm trying to set up a routing definition in my project which will allow users to have profiles accessible by simply using their username as the only parameter in the url, like <code>www.example.com/username</code> as opposed to <code>www.example.com/user/view/username</code></p> <p>I've set up a catch all route to go to an action which checks if the user exists, as the last route in the config file, and it works, but it over rides all of the basic routing that cake does. Meaning that I would have to define a route for every controller I want to provide access to just to make sure I never make it to the catchall. My routes:</p> <pre><code>Router::connect('/events/edit/*', array('controller' =&gt; 'events', 'action' =&gt; 'edit')); Router::connect('/events/view/*', array('controller' =&gt; 'events', 'action' =&gt; 'view')); Router::connect('/events/add', array('controller' =&gt; 'events', 'action' =&gt; 'add')); Router::connect('/events/*', array('controller' =&gt; 'events', 'action' =&gt; 'index')); Router::connect('/*', array('controller' =&gt; 'users', 'action' =&gt; 'view')); </code></pre> <p>So, this will allow me to access my events page, but any other pages get sent to the second router, expectedly.</p> <p>What I'd like is to have is a route that does the basic cake function of <code>/controller/action/param</code> if the controller exists, but have it fall through to the last route which goes to the <code>user/view</code> page otherwise.</p> <p>My question is, for what I'm trying to accomplish, am I doing this the right way? If I need to define a route for every controller I want access to, I will, but I have to think there's a better way to accomplish this.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload