国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP開(kāi)發(fā) Detailed explanation of Zend Framework router usage examples

Detailed explanation of Zend Framework router usage examples

Jan 06, 2017 am 09:48 AM

The examples in this article describe the usage of Zend Framework router. Sharing it with you for your reference, the details are as follows:

Routing is a process in which it removes the endpoint of the URI (following the URI part of the base URL) and breaks it into parameters to decide which module, Which controller and which action should accept the request.

Modules, controllers, actions, and their parameters are packaged into Zend_Controller_Request_Http objects.

Using the router

In order to use the router correctly, it must be initialized.

Creating a router can be achieved through the getRouter() method of the front-end controller instance. This method does not require any parameters, and executing this method can return a Zend_Controller_Router_Rewrite object.

After creating the router, you need to add some user-defined routes. This operation can be achieved through the addRoute() method of the Zend_Controller_Router_Rewrite object.

Code:

<?php
/**
演示創(chuàng)建路由器的過(guò)程
*/
require_once &#39;Zend/Controller/Front.php&#39;;    //引用Zend_Controller_Front.php
$ctrl = Zend_Controller_Front::getInstance();  //創(chuàng)建一個(gè)前端控制器
$router = $ctrl->getRouter();          //返回一個(gè)默認(rèn)路由,前端控制器功能很強(qiáng)大啊
$router->addRoute(&#39;user&#39;,new Zend_Controller_Router_Route(&#39;user/:username&#39;,array(&#39;controller&#39;=>&#39;user&#39;,&#39;action&#39;=>&#39;info&#39;)));

4 basic routes

1. Default route

Definition: The default route is a simple Zend_Controller_Router_Route_Module object named 'default' stored in RewriteRouter.

2. Standard framework routing

Definition: Zend_Controller_Router_Route is a standard framework routing.

Example:

<?php
//定義標(biāo)準(zhǔn)框架路由
$route = new Zend_Controller_Router_Route(&#39;author/:username&#39;,
array(
  &#39;controller&#39;=>&#39;profile&#39;,
  &#39;action&#39;=>&#39;userinfo&#39;
));
//向路由器中添加定義的路由
$router->addRoute(&#39;user&#39;,$route);

Note: I said that I was dizzy, the log is not easy to code, and I don’t understand it well.

3. Static routing

Definition: A specific route is set to form Zend_Controller_Router_Route_Static.

Example:

<?php
//定義靜態(tài)路由
$route = new Zend_Controller_Router_Route_Static(
&#39;login&#39;,
array(
  &#39;controller&#39;=>&#39;auth&#39;,
  &#39;action&#39;=>&#39;login&#39;
));
//向路由器中添加定義的路由
$router->addRoute(&#39;login&#39;,$route);

The above route will match the URL of http://domain.com/login and dispatch it to the AuthController: :loginAction() method.

4. Regular expression routing

Zend_Controller_Router_Route_Regex

Case:

<?php
//正則表達(dá)式路由
$route = new Zend_Controller_Router_Route_Regex(
  &#39;archive/(\d+)&#39;,
  array(
    &#39;controller&#39;=>&#39;archive&#39;,
    &#39;action&#39;=>&#39;show&#39;
  ));
//向路由器中添加定義的路由
$router->addRoute(&#39;archive&#39;,$route);

Analysis:

The dynamic part (content after "/") in the first parameter of the regular expression routing definition is no longer a variable, but a regular sub-pattern.

In this example, after successfully matching http://domain.com/archive/2008, the following array of result values ??will be returned.

$values = array(
1=>&#39;2008&#39;,
&#39;controller&#39;=>&#39;archive&#39;,
&#39;action&#39;=>&#39;show&#39;
);

Postscript:

I said there are too many concepts and it is very difficult.

I hope this article will be helpful to everyone’s PHP programming based on the Zend Framework framework.

For more detailed examples of Zend Framework router usage and related articles, please pay attention to the PHP Chinese website!

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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)