Home > php教程 > PHP开发 > body text

Zend Framework front-end controller usage example

高洛峰
Release: 2017-01-06 09:54:58
Original
1138 people have browsed it

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();
Copy after login

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();
Copy after login

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 &#39;Zend/Controller/Front.php&#39;;    //加载Zend_Controller_Front类
$front = Zend_Controller_Front::getInstance();  //获取前端控制器实例
$front->setParam(&#39;name&#39;,&#39;张三&#39;);        //设定前端控制器参数
$name = $front->getParam(&#39;name&#39;);        //获取设定的参数
echo $name;
echo "<p>";
$array = array(
  &#39;g_n&#39;=>&#39;联想&#39;,
  &#39;g_c&#39;=>&#39;5000&#39;,
  &#39;g_a&#39;=>&#39;北京&#39;,
  &#39;g_p&#39;=>&#39;联想集团&#39;
);
$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>";
}
Copy after login

The result is:

张三
name的值为:张三
g_n的值为:联想
g_c的值为:5000
g_a的值为:北京
g_p的值为:联想集团
Copy after login

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!

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template