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

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

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
