1

I would like to have a route setup on my CakePHP app that will accomplish the following:

  • I have my app setup to use Slugs that usually generate addresses as

http://www.domain.com/articles/view/my-favorite-cakephp-application

  • However, I would like the address to display as

http://www.domain.com/articles/my-favorite-cakephp-application

How can I accomplish that using routes.

Thank you!

Dave
  • 28,833
  • 23
  • 113
  • 183
AKKAweb
  • 3,795
  • 4
  • 33
  • 64

1 Answers1

-1

in routes.php

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

Anh Pham
  • 5,431
  • 3
  • 23
  • 27
  • That does not work since it will try to route anything that is there. For example if I have http://www.mydomain.com/articles/index, it will send it to http://www.mydomain.com/articles/view and send it again to http://www.mydomain.com/articles/view causing an infinite loop. – AKKAweb Jul 16 '11 at 15:18
  • if you have other methods (index, add, etc.) just add the routes for them before that. So for examples: Router::connect( '/articles/', array('controller' => 'articles', 'action' => 'index') );Router::connect( '/articles/add/*', array('controller' => 'articles', 'action' => 'add') );Router::connect( '/articles/*', array('controller' => 'articles', 'action' => 'view') ); If you use prefix, you also need to add rules for them too. – Anh Pham Jul 17 '11 at 00:55
  • Yeah that would be too complicated. However, I got to say you were very close. I was able to fix this based on the following post: http://stackoverflow.com/questions/5109461/cakephp-how-to-do-reverse-routing-with-slug . Per this guy's suggestion, I changed my route to `Router::connect('/article/*',array('controller' => 'articles', 'action' => 'view'));`. The only thing you missed is that in the link the controller needs to be singular (`article` instead of `articles`). Excellent though.... – AKKAweb Jul 17 '11 at 04:45