PHP Development Framework KOHANA3 Custom Routing Setup Example _php instance

Source: Internet
Author: User
Tags kohana

Due to the Kohana framework in the domestic user less, and the new version with Kohana2. X the difference is too large, plus kohana3 data for more than English. Let a lot of kohana interested in, want to learn students can only hope K sigh. As the company recently turned to KOHANA3 development (kohana3.1.0 Stable Edition), so I took the opportunity to take a serious look at the official information. Benefit A lot, Borrow personal small station, share to everybody. Today, let's say Kohana routing settings.
Again, I use the ko3.1.0 and Ko3 have the difference.
In fact, Kohana3 's routing settings are simple. Open the bootstrap.php under the application file and find the Route::set, and see the following default route:

Copy Code code as follows:
Route::set (' Default ', ' ((//)) ')
->defaults Array (
' Controller ' => ' welcome ',
' Action ' => ' index ',
));

This is the default route, you can see that it is the composition of this. Name, controller, action, parameters. In particular, each route must specify the default control and action, typically index.

How to create a custom route, in fact, is the same as the default, but just add what you want to add. For example, there is a product list page that needs to get the ID of the product type and the current page number.
Routing can be set like this

Copy Code code as follows:

Route::set (' Product ', ' product/((/) (/)) ')
->defaults Array (
' Controller ' => ' product ',
' Action ' => ' index ',
' ID ' =>0,
Some examples of ' page ' =>0//here are null, but I used an error.
));

Here, the first product is the name, followed by the focus of the place, product is the controller,/action is the action, must be so written. The back (/<>) inside is the parameter. Get here in the page parameter is this, $id = $this-> Request->param (' id '), the ID inside this, must be the same as the ID name inside the route.
Students need to refer to this example to change, should be able to. Outstanding, I highly recommend that you look at the 2 station things

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

Can be compared to see, I believe we can play Kohana, refueling!!

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.