This article describes the usage of the Zend Framework front-end controller. Share it for your reference, as follows:
Common methods
()
Function: Used to obtain front-end controller instance.
The code is as follows:
<?php $front = Zend_Controller_Front::getInstance();
Execute the above code and create a front-end controller instance.
()
Function: Used to notify the distributor where to look for action controller action controller class file.
()
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
()
Function: Clear all current settings
2.(set|get)DefaultControllerName()
Function: Assign another name to the default controller and get the current value
3.(set|get)DefaultActionName()
Function: Assign another name to the default action and get the current value
4.(set|get)Request()
Function: Specify the request class or object used during the distribution process, and obtain the current request object
5.(set|get)Router()
Function: Specify the router class or object used during the distribution process, and obtain the current object
6.(set|get)Response()
Function: Specify the response class or object used during the distribution process, and obtain the current object
Front-end controller parameters
(name,name,value)
Function: Single parameter name of single parameter value with set value
(array $params)
Function: Set multiple parameters at once by associating arrays
($name)
Function: Get a single parameter through the $name identifier
()
Function: Get the entire parameter list at once
()
Function: Clear one parameter (passing a single string), multiple parameters (passing an array), all parameters (no parameters)
example:
<?php require_once 'Zend/Controller/'; //Load the Zend_Controller_Front class$front = Zend_Controller_Front::getInstance(); //Get the front-end controller instance$front->setParam('name','Zhang San'); //Set the front-end controller parameters$name = $front->getParam('name'); //Get the set parametersecho $name; echo "<p>"; $array = array( 'g_n'=>'Lenovo', 'g_c'=>'5000', 'g_a'=>'Beijing', 'g_p'=>'Lenovo Group' ); $front->setParams($array); $g = $front->getParams(); foreach($g as $k=>$v){ echo $k."The value is:".$v; echo "<p>"; } $front->clearParams(); $last = $front->getParams(); foreach($last as $k=>$v){ echo $k."The value is:".$v; echo "<p>"; }
The result is:
Zhang San nameThe value of:Zhang San g_nThe value of:Lenovo g_cThe value of:5000 g_aThe value of:Beijing g_pThe value of:Lenovo集团
Since the parameters are cleared, there is no data output on the second call.
For more information about Zend, please visit the special topic of this site:Zend FrameWork Framework Introduction Tutorial》、《Summary of excellent development framework for php》、《Yii framework introduction and common techniques summary》、《ThinkPHP Introduction Tutorial》、《PHP object-oriented programming tutorial》、《PHP+mysql database operation tutorial"and"Summary of common database operation techniques for php》
I hope that this article will be helpful to everyone's PHP programming based on the Zend Framework framework.