tags:

views:

51

answers:

3

Why we are using routing in cakePHP and what would be the basic approaches for implementation...?

A: 

http://book.cakephp.org/view/310/Configuration

<?php
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
?> 
+1  A: 

Why

Because it allows you to decouple your URLs from your controller actions. You can name your controllers and actions in a way that makes sense internally, and invoke them using URLs that do not need to bear any resemblance to your internal naming scheme.
FooApiVersion1Controller::internal_beta_method() can be invoked by the URL /api/v1/method, and you can swap out the controller or method at any time without needing to change the URL.

How

Read the manual. http://book.cakephp.org/view/945/Routes-Configuration

deceze
+1  A: 

Routing allows aliasing and routing(!) of URLs. It gives us a cleaner, more controlled interface and underpins the functioning of CakePHP.

The first step would be to read the appropriate chapter in the book: http://book.cakephp.org/view/542/Defining-Routes (1.2) or http://book.cakephp.org/view/948/Defining-Routes (1.3)

Then look at the routes.php file (app/config/routes.php) to understand how it goes together.

Finally, when you know what you want to do (we don't because you haven't told us), try it debug it and use it.

Leo