views:

38

answers:

1

Hi, I want to enable this kind of routing in my site where users can create their vanity urls

test.com/[user-url]

but also dont want to ruin the routing for my existing controllers test.com/users test.com/business test.com/admin

so I added this to my routes.php

Router::connect('/*', array('controller' => 'business', 'action' => 'view'));

is it possible to use regex for the '/*' so I can have exclude the routes for my controllers?

p.s. pretty much like the routing in facebook

+1  A: 

The following I have adapted from something that I used for my own pages; I have not tested it for your use case. It should pass all requests to Users controller except search and contact

I also uses custom route classes http://mark-story.com/posts/view/using-custom-route-classes-in-cakephp

App::import('Lib', 'routes/UserUrlRoutes');

// 
Router::connect(
    '/:slug', 
    array('controller' => 'users', 'action' => 'view'), 
    array(
        'routeClass' => 'UserUrlRoute', 
        'slug' => '(?!search|contact)'
        )
    );
Router::connect('/:slug/*', array('controller' => 'users', 'action' => 'view'), array('routeClass' => 'UserUrlRoutes'));
sam
exactly what i need thanks!
wnoveno