Zend Framework动作助手(Zend_Controller_Action_Helper)用法详
本文实例讲述了Zend Framework动作助手(Zend_Controller_Action_Helper)用法。分享给大家供大家参考,具体如下: 通过助手模式,可以把一些经常使用的功能模块做封装,从而在可以在需要的地方灵活使用,主要是在action使用。 Zend Framework中有两种助手,动
本文实例讲述了Zend Framework动作助手(Zend_Controller_Action_Helper)用法。分享给大家供大家参考,具体如下:
通过助手模式,可以把一些经常使用的功能模块做封装,从而在可以在需要的地方灵活使用,主要是在action使用。
Zend Framework中有两种助手,动作助手(Zend_Controller_Action_Helper)和试图助手(Zend_View_Helper)。
动作助手可以向任何Zend_Controller_Action的衍生动作控制器中,即时的加入功能(runtime and/or on-demand functionality),以使得增加公共的动作控制器功能时,尽量减少衍生动作控制器类的必要。
动作助手在需要调用时加载,可以在请求的时候(bootstrap)或者动作控制器创建的时候(init())实例化。
涉及到的相关文件
在/library/Zend/Controller/Action/中
│ Exception.php
│ HelperBroker.php
│ Interface.php
│
├─Helper
│ │ Abstract.php
│ │ ActionStack.php
│ │ AjaxContext.php
│ │ AutoCompleteDojo.php
│ │ AutoCompleteScriptaculous.php
│ │ Cache.php
│ │ ContextSwitch.php
│ │ FlashMessenger.php
│ │ Json.php
│ │ Redirector.php
│ │ Url.php
│ │ ViewRenderer.php
│ │
│ └─AutoComplete
│ Abstract.php
│
└─HelperBroker
PriorityStack.php
常见的动作助手有:
FlashMessenger 用来处理Flash Messenger会话;
Json 用来解码和发送 JSON 响应;
Url 用于创建Urls;
Redirector 提供另一种实现方式,帮助程序重定向到内部或者外部页面;
ViewRenderer 自动的完成在控制器内建立视图对象并渲染视图的过程;
AutoComplete 自动响应 AJAX 的自动完成;
ContextSwitch 和 AjaxContext 为你的动作提供替代响应格式;
Cache 实现cache的相关操作;
ActionStack 用于操作动作堆栈。
动手的几种实例化使用方式
1.通过Zend_Controller_Action的 $_helper成员的getHelper()方法。直接调用getHelper(),传入助手的名称即可。
1 2 3 |
|
2.直接通过访问的_helper助手的属性对应的助手对象。
1 |
|
Zend_Controller_Action_HelperBroker
中文名称译作"助手经纪人",顾名思义,是动作助手的中间人。
在动作的实例化使用的方式的第二种方式就是通过Zend_Controller_Action_HelperBroker的魔术方法__get()来实现的。
助手经纪人用于注册助手对象和助手路径以及获取助手等等功能。
Zend_Controller_Action_HelperBroker的实现以及常用方法列表
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
助手经纪人的常见用法:
一、注册一个助手
1.
1 |
|
2.通过addPrefix()方法带有一个类前缀参数,用来加入自定义助手类的路径。
要求前缀遵循Zend Framework的类命名惯例。
1 2 |
|
3.使用addPath()方法第一个参数为一个目录,第二个为类前缀(默认为'Zend_Controller_Action_Helper')。
用来将自己的类前缀映射到指定的目录。
1 2 3 |
|
二、判读助手是否存在
使用hasHelper($name)方法来判定助手经纪人中是否存在某助手,$name是助手的短名称(去掉前缀的):
1 2 3 4 |
|
从助手经纪人中获取助手有两个静态方法:getExistingHelper() 和 getStaticHelper() 。getExistingHelper()将获取助手仅当它以前调用过或者显性地通过助手经纪人注册过,否则就抛出一个异常。getStaticHelper() 的做法和getExistingHelper()一样,但如果还没有注册助手堆栈,它将尝试初始化助手,为获取你要配置的的助手,getStaticHelper()是一个好的选择。
两个方法都带一个参数,$name,它是助手的短名称(去掉前缀)。
1 2 3 4 5 6 7 8 9 10 |
|
三、removeHelper($name)删除助手经纪人中的某个助手,$name是助手的短名称。
1 2 3 4 |
|
更多关于zend相关内容感兴趣的读者可查看本站专题:《Zend FrameWork框架入门教程》、《php优秀开发框架总结》、《Yii框架入门及常用技巧总结》、《ThinkPHP入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。

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

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)

Hot Topics











.NET Framework 4 is required by developers and end users to run the latest versions of applications on Windows. However, while downloading and installing .NET Framework 4, many users complained that the installer stopped midway, displaying the following error message - " .NET Framework 4 has not been installed because Download failed with error code 0x800c0006 ". If you are also experiencing it while installing .NETFramework4 on your device then you are at the right place

Whenever your Windows 11 or Windows 10 PC has an upgrade or update issue, you will usually see an error code indicating the actual reason behind the failure. However, sometimes confusion can arise when an upgrade or update fails without an error code being displayed. With handy error codes, you know exactly where the problem is so you can try to fix it. But since no error code appears, it becomes challenging to identify the issue and resolve it. This will take up a lot of your time to simply find out the reason behind the error. In this case, you can try using a dedicated tool called SetupDiag provided by Microsoft that helps you easily identify the real reason behind the error.

The two-dimensional open world action game "Wang Yue" owned by Shiyue Network recently released a new production information "48 Days Lives a New World", which introduced a series of optimization content of 48 Days since the last time it released production information, mainly the game screen. Iteration on performance. Among them, the display of the character UI interface has aroused heated discussions among many players, saying that it looks very familiar. Perhaps this kind of character display with multiple lenses running smoothly is becoming a new trend. Producer Hua Tao previously stated that the game has been in production for more than two years and will start its first test in the first quarter of 2024. Yesterday, the official also released a reservation video ""It seems like a pleasant afternoon"". It must be that the first test is not far away.
![SCNotification has stopped working [5 steps to fix it]](https://img.php.cn/upload/article/000/887/227/168433050522031.png?x-oss-process=image/resize,m_fill,h_207,w_330)
As a Windows user, you are likely to encounter SCNotification has stopped working error every time you start your computer. SCNotification.exe is a Microsoft system notification file that crashes every time you start your PC due to permission errors and network failures. This error is also known by its problematic event name. So you might not see this as SCNotification having stopped working, but as bug clr20r3. In this article, we will explore all the steps you need to take to fix SCNotification has stopped working so that it doesn’t bother you again. What is SCNotification.e

Microsoft Windows users who have installed Microsoft.NET version 4.5.2, 4.6, or 4.6.1 must install a newer version of the Microsoft Framework if they want Microsoft to support the framework through future product updates. According to Microsoft, all three frameworks will cease support on April 26, 2022. After the support date ends, the product will not receive "security fixes or technical support." Most home devices are kept up to date through Windows updates. These devices already have newer versions of frameworks installed, such as .NET Framework 4.8. Devices that are not updating automatically may

The classic online game "Dragon Nest" is about to be launched on Steam. The store page is currently online. The publisher is Shengqu Games. The planned release date will be announced soon. The language only supports Chinese. "Dragon Nest" is a 3D lock-free innovative competitive online game. With its unique operation method, dreamy game graphics, refreshing combo battles and intense PVP experience, it has become an action-adventure game loved by Valley fans.

There are various actions that can be obtained in Eternal Calamity. Players can use these actions when playing the game. There is a subject three action in the game that can be obtained. After the player obtains it, he can use this action to jump to subject three. This time we will also introduce the specific method of obtaining this action, so you can take a look. How to obtain the three actions of Eternal Calamity Subject 1. First enter the game, find the mall in the game interface, and click to enter. 2. Then check the new products in the mall and find the action called [Silk Smooth Combo]. This action is the third action. 3. The original price of the action is 1,000 gold bricks, and it is 500 gold bricks when it is discounted. Players can get this action after purchasing it. 4. After the purchase is successful, you can get this action.

PHP implementation framework: ZendFramework introductory tutorial ZendFramework is an open source website framework developed by PHP and is currently maintained by ZendTechnologies. ZendFramework adopts the MVC design pattern and provides a series of reusable code libraries to serve the implementation of Web2.0 applications and Web Serve. ZendFramework is very popular and respected by PHP developers and has a wide range of
