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(); //获取前端控制器实例 $front->setParam('name','张三'); //设定前端控制器参数 $name = $front->getParam('name'); //获取设定的参数 echo $name; echo "<p>"; $array = array( 'g_n'=>'联想', 'g_c'=>'5000', 'g_a'=>'北京', 'g_p'=>'联想集团' ); $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的值为:联想 g_c的值为:5000 g_a的值为:北京 g_p的值为:联想集团
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

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

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

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.