CakePHP route settings connect and parseExtensions

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.