In order for your route to process different types of files, you need to add a line in your route configuration file: connect function definition
Connect ($ route, $ default = array (), $ params = array ())
Returns this object's routes array. Returns false if there are no routes available.
$ Route |
String |
An empty string, or a route string "/" |
Required |
(No default) |
$ Default |
Array |
NULL or an array describing the default route |
Optional |
Array () |
$ Params |
Array |
An array matching the named elements in the route to regular expressions which that element shoshould match. |
Optional |
Array () |
Connect example application
Router: connect ('/', array ('controller' => 'pages', 'Action' => 'display', 'home '));
When you access siteurl/or siteurl/index. php/, the controller is pages, the action is display, and the view template file is/app/views/pages/home. ctp.
In addition, the connect function supports pattern matching. For example:
Router: connect ('/pages/*', array ('controller' => 'Page', 'Action' => 'display '));
Meaning: any website of siteurl/pages/* or siteurl/index. php/pages/* matches? Controller = pages & action = display.
ParseExtensions file extension
Router: parseExtensions ()
In order for your route to process different types of files, you need to add a line in your route configuration file:
Router: parseExtensions ('html', 'RSS ', 'xml ');
This tells the route to remove the matching file extension and then process the remaining part.
If you want to create a URL, such as/page/title-of-page.html, you must create your route as described below:
Router::connect('/page/:title', array('controller' => 'pages', 'action' => 'view'), array('pass' => array('title') ));
Then you can create and access the link pointing to the route as follows.
Conclusion
The above are translated from the official CakePHP API and Cook Book.