Thursday, August 30, 2012

Re: One slug route connected to multiple controllers?

If you use different constants on your slug, like "DisPersonIsKewl " or "TehEpicStartup", I think you can do it with regular expression.


Well, I think it could work. If the slug match with the first regular expression, it will call the StartupsController... if it doesn't, it will check the second expression... if it match, the controller called will be the PeopleController.

I don't know if the regular expressions I used are correct, it was just an example.

Att,

--

Luiz Antonio S Messias
Desenvolvedor Web




2012/8/30 42startups <hello@42startups.com>
Hi

So I have two controllers: Startups and People

But I'd like a direct slug to link to either.

eg:
domain.com/TehEpicStartup - should go to startups->view
domain.com/DisPersonIsKewl - should go to people->view

Is there an easy option here, or do I need to create a separate controller, or should I just go with the default domain.com/startups/TehEpicStartup and domain/people/DisPersonIsKewl ??

In routes.php:

Router::connect(
   '/:slug', 
   array(
       'controller' => 'startups', 
       'action' => 'view'
       ), 
   array(
    'slug' => '[a-zA-Z0-9_-]+'
   )
);


Cheers! 

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 

No comments: