Sanjay Shah
Sanjay Shah

Reputation: 2809

Use of Routing in CakePHP

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

Upvotes: 0

Views: 200

Answers (3)

Leo
Leo

Reputation: 6571

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.

Upvotes: 1

deceze
deceze

Reputation: 521995

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

Upvotes: 1

Sachin R
Sachin R

Reputation: 11876

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

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

Upvotes: 0

Related Questions