Example of custom route settings in PHP development framework kohana3

Source: Internet
Author: User
This article mainly introduces the example of custom route settings in the PHP development framework kohana3. kohana is a pure PHP5 development framework. For more information, see kohana framework users in China, in addition, the new version is significantly different from kohana2.X, and kohana3 documents are mostly in English. so many people who are interested in kohana can only look at K to sigh. as the company recently switched to kohana3 development (kohana3.1.0 stable version), I took the opportunity to carefully read the official materials. I have benefited a lot and shared it with you on my personal website. today, let's talk about kohana route settings.
Again, I use ko3.1.0 and ko3.
In fact, the Route settings of kohana3 are very simple. open bootstrap. php in the application file and find the Route: set. the default Route is shown as follows:

The code is as follows: Route: set ('default ','((/(/)))')
-> Defaults (array (
'Controller' => 'Welcome ',
'Action' => 'index ',
));

This is the default route. it can be seen that its composition is like this. name, controller, action, parameter. in particular, each route must specify the default control and action, which is generally index.

How to create a custom route is actually the same as the default method, except to add what you want to add. for example, if you have a product list page, you must obtain the product type ID and current page number.
You can set routes in this way.
The code is as follows:
Route: set ('product', 'product /((/)(/))')
-> Defaults (array (
'Controller' => 'Product ',
'Action' => 'index ',
'Id' => 0,
'Page' => 0 // some examples here are NULL, but I used an error.
));

Here, the first product is the name, followed by the focus, the product is the controller,/action is the action, so it must be written in this way. the parameters are in the following (/<>. obtain the parameter here on the page. $ id = $ this-> request-> param ('id'). the id in this parameter must be the same as the id in the route.
You can refer to this example to modify the information you need. if not, we strongly recommend that you read the two websites.

1. http://kohanaframework.org/3.1/guide (official online documentation)
2. http://kerkness.ca/wiki/doku.php (unofficial Wikipedia, the example is better than official but version 3.0)

Let's look at the comparison. I believe everyone can play with kohana. come on !!

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.