PHP development framework kohana3 custom route setting example, framework kohana3_PHP tutorial

WBOY
Release: 2016-07-13 10:23:17
Original
915 people have browsed it

PHP development framework kohana3 custom route setting example, framework kohana3

Because the kohana framework has fewer users in China, and the new version is too different from kohana2. Recently I switched to kohana3 development (kohana3.1.0 stable version), so I took this opportunity to carefully read the official information. I benefited a lot, so I shared it with everyone through my personal website. Today, I will talk about the routing settings of kohana. .
Let me say it again, I am using ko3.1.0 which is different from ko3.
In fact, the routing setting of kohana3 is very simple. Open bootstrap.php under the application file, find Route::set, and you will see the following default route:

Copy code The code is as follows:
Route::set('default', '((/(/)))')
->defaults(array(
'controller' => 'welcome',
'action' => 'index',
));

This is the default route. You can see that its composition is like this. Name, controller, action, parameters. It is particularly important to point out that each route must specify the default control and action. Generally, is index.

How to create a custom route? In fact, it is the same as the default writing method, except that you add what you want to add. For example, if there is a product list page, you need to get the ID of the product type and the current page number.
Routing can be set like this

Copy code The code is as follows:

Route::set('product', 'product/((/)(/))')
->defaults(array(
'controller' => 'product',
'action' => 'index',
'id' =>0,
'page' =>0//In some examples it is NULL, but I used it to report an error.
));

Here, the first product is the name, and the following is the key point. Product is the controller, and /action is the action. It must be written like this. The following (/<>) are the parameters. On the page The way to get this parameter is like this, $id = $this->request->param('id'), the id in this must be the same as the id name in the route.
Students who need it can refer to this example to modify it, and it should be fine. I highly recommend everyone to read the two sites

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

You can compare and see, I believe everyone can play kohana, come on!!

How to configure the php kohana framework after downloading it?

not found MODPATH\\database\\classes\\kohana\\db.php [ 63 ] 58 * @param Please indicate how you call database or ORM in the process. It may be that the method you call is wrong. .

How to use the php development framework, new to the framework

Normally I don't speak either. Today I’ll write a code for you to see: 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 the
found in the database echo $p['name'];
}

This is how I usually write PHP. When programming with arrays,
most of them output SQL statements and nest HTML in the page, which makes the page bloated and difficult to maintain and expand.
It is easier to modify after layering in this way

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/840645.htmlTechArticlePHP development framework kohana3 Custom routing setting example, framework kohana3 Since the kohana framework has fewer users in China, and the new version It is very different from kohana2.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template