Friday, August 31, 2012

Re: One slug route connected to multiple controllers?

Hi,

A possible solution is to use a subclass of CakeRoute to do any extra check you need, if it is really a variable slug. It's the most powerful solution for routing, but maybe it is really slower than direct routing.

There isn't a lot of documentation in the Cake book, but you can take a look in this link.

http://book.cakephp.org/2.0/en/development/routing.html#custom-route-classes

Regards,

2012/8/31 42startups <hello@42startups.com>
Eh, the slugs are random but unique (I'm pulling them in from an external API via a cron job).

It would be nice if I could do a find() within the routes.php file and then assign a controller based on the result. But alas.

I think I'll just have a top-level slug for one of the models.

Thanks anyway!

Cheers


On Thu, Aug 30, 2012 at 9:46 PM, Tony Messias <tonyzrp@gmail.com> wrote:
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.
 
 

--
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: