The example in this article describes the usage of Zend Framework front-end controller. Share it with everyone for your reference, the details are as follows:
Common methods
1.getInstance()
Function: Used to obtain the front-end controller instance.
The code is as follows:
<?php $front = Zend_Controller_Front::getInstance();
Executing the above code will create a front-end controller instance.
2.setControllerDirectory()
Function: Used to notify the distributor where to find the action controller action controller class file.
3.getControllerDirectory()
Function: Used to obtain the current location of the controller directory
The code is as follows:
<?php $front = Zend_Controller_Front::getInstance(); $dire = $front->getControllerDirectory();
Environment accessor method
1.resetInstance()
Function: Clear all current settings
2.(set|get)DefaultControllerName()
Function: Specify another name for the default controller, and get the current value
3.(set|get)DefaultActionName()
Function: Specify another name for the default action, and get the current value
4.(set|get)Request()
Function: Specify the request class or object used in the distribution process, and obtain the current request object
5.(set|get )Router()
Function: Specify the router class or object used in the distribution process, and obtain the current object
6.(set|get)Response()
Function: Specify the router class or object used in the distribution process The response class or object, and getting the current object
Front-end controller parameters
1.setParam(name,name,value)
Function: Set a single parameter value with value A single parameter name
2.setParams(array $params)
Function: Set multiple parameters at once through an associative array
3.getParam($name)
Function: Get a single parameter through the $name identifier
4.getParams()
Function: Get the entire parameter list at one time
5.clearParams()
Function: Clear a parameter (pass Enter a single string), multiple parameters (pass in an array), all parameters (no parameters)
Example:
<?php require_once 'Zend/Controller/Front.php'; //加載Zend_Controller_Front類 $front = Zend_Controller_Front::getInstance(); //獲取前端控制器實(shí)例 $front->setParam('name','張三'); //設(shè)定前端控制器參數(shù) $name = $front->getParam('name'); //獲取設(shè)定的參數(shù) echo $name; echo "<p>"; $array = array( 'g_n'=>'聯(lián)想', 'g_c'=>'5000', 'g_a'=>'北京', 'g_p'=>'聯(lián)想集團(tuán)' ); $front->setParams($array); $g = $front->getParams(); foreach($g as $k=>$v){ echo $k."的值為:".$v; echo "<p>"; } $front->clearParams(); $last = $front->getParams(); foreach($last as $k=>$v){ echo $k."的值為:".$v; echo "<p>"; }
The result is:
張三 name的值為:張三 g_n的值為:聯(lián)想 g_c的值為:5000 g_a的值為:北京 g_p的值為:聯(lián)想集團(tuán)
Because the parameters are cleared, no data is output during the second call.
I hope this article will be helpful to everyone’s PHP programming based on the Zend Framework framework.
For more Zend Framework front-end controller usage examples and related articles, please pay attention to the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
