Example of custom route settings for the PHP development framework kohana3. tutorial on the framework kohana3_PHP

Source: Internet
Author: User
Tags kohana
Example of custom route settings for the PHP development framework kohana3. Example of custom route settings for the PHP development framework kohana3. the kohana3 framework has a small number of users in China, and the new version is too different from kohana2.X. In addition, the kohana3 documents are mostly in English. let the PHP development framework kohana3 customize the routing settings example, the framework kohana3

Because the kohana framework has few users in China, and the new version is too different from kohana2.X, the 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 !!


How can I configure the php kohana framework after it is downloaded?

Not found MODPATH \ database \ classes \ kohana \ db. php [63] 58 * @ param please state how you call the database or ORM in the process, or the method you call may be incorrect.
 

How to use the php development framework?

I usually do not speak either. Write a code today to show you: simple Model layer
Product. class. php:
Class product {
Public function getAllProducts (){
$ Q = "SELECT * FROM Product ";
$ R = $ db-> query ($ q );
$ ProArr = array ();
While ($ row = db-> fetchAssoc ($ r )){
$ ProArr [] = $ row;
}
Return $ proArr;
}
}
?>
View and control layer:
Getallproducts. php:
$ Product = new product ();
$ Ps = $ product-> getAllProducts ();

Foreach ($ ps as $ p ){
// Output
Echo $ p ['name'];
}

I usually write more PHP statements like this, that is, most of them program arrays,
Most of them are SQL statements output on the page, nested HTML, the page looks bloated, not easy to maintain and expand
In this way, it is easier to modify the layer.

Example of custom routing settings for Ingress. the kohana3 framework has a small number of users in China, and the new version is too different from kohana2.X. In addition, the kohana3 documentation is mostly in English...

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.