PHP Development Framework KOHANA3 Custom Routing Setup example, Framework kohana3_php Tutorial

Source: Internet
Author: User
Tags kohana

PHP Development Framework KOHANA3 Custom Routing Settings example, framework Kohana3


Due to the Kohana framework in the domestic users less, and the new version and Kohana2. X difference is too big, plus kohana3 data is more English. Let a lot of kohana interested, want to learn the students can only hope K sigh. As the company recently turned to KOHANA3 development (kohana3.1.0 stable version), so I took the opportunity to carefully read the official information. A lot of benefits, Borrow personal small station, share to everybody. Today, let's just say Kohana's routing settings.
Again, I use the ko3.1.0 and Ko3 are different.
In fact, Kohana3 's routing settings are simple. Open the bootstrap.php under the application file and find the Route::set, which will look like the default route:

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

This is the default route, you can see its composition is like 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, and the default is the same way, just add the things 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.
Routes can be set like this
Copy the Code code as follows:
Route::set (' Product ', ' product/(/) (/) ')
->defaults (Array (
' Controller ' = ' product ',
' Action ' = ' index ',
' ID ' =>0,
Some examples of ' page ' =>0//are null here, but I used an error.
));

Here, the first product is the name, the following is the focus of the place, product is the controller,/action is the action, must write this. The back (/<>) inside is the parameter. Get here in the page parameter is this, $id = $this Request->param (' id '), the inside ID, must be the same as the ID name inside the route.
The students need to refer to this example to change, should be able to. Outstanding, we strongly recommend that you look at 2 stations of things

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

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


How to configure PHP Kohana framework after download?

Not found modpath\\database\\classes\\kohana\\db.php [+] * @param Please specify how you call database or ORM in the process, or the method you are calling.

How to use the PHP development framework, just contact the framework

product.class.php:
!--? 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:
!--? php
$product =new product ();
$ps = $product->getallproducts ();

foreach ($ps as $p) {
//Output database detected
echo $p [' name '];
}

That's what I write. PHP said much, that is, most of the array of programming,
Most of the output of SQL statements in the page, nested HTML, the page is bloated, difficult to maintain and expand
such layered after the change is simple
 

http://www.bkjia.com/PHPjc/840645.html www.bkjia.com true http://www.bkjia.com/PHPjc/840645.html techarticle PHP Development Framework KOHANA3 Custom Routing Settings example, framework KOHANA3 due to Kohana framework in the domestic user less, and the new version with Kohana2. X difference is too big, plus kohana3 information more English. Let the

  • 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.