In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you the "Zend Framework custom Helper class related matters needing attention", the content is easy to understand, clear, hope to help you solve the doubt, the following let the editor lead you to study and learn "Zend Framework custom Helper class related considerations there are" this article.
The details are as follows:
Write custom Helper classes
Writing custom Helper classes is easy, as long as you follow the following principles:
The ① class name must be the name of Zend_View_Helper_*,* that is helper. For example, if you are writing a class called "specialPurpose", the class name will be at least "SpecialPurpose". In addition, you should prefix the class name, and it is recommended that "View_Helper" be part of the prefix: "My_View_Helper_SpecialPurpose". (note case) you will need to pass the prefix (without underscores) to addHelperPath () or setHelperPath ().
There must be a method of public in the ② class, which has the same name as the helper class. This method will be executed when your template calls "$this- > specialPurpose ()". In our "specialPurpose" example, the corresponding method declaration can be "public function specialPurpose ()".
③ generally speaking, Helper classes should not have echo or print or other forms of output. It just needs to return the value. The returned data should be escaped.
The name of the ④ class file should be the name of the helper method, for example, in the "specialPurpose" example, the file should be saved as "SpecialPurpose.php".
Put the files of the helper class under your helper path, and Zend_View will automatically load, instantiate, persist, and execute.
The three-point class file name, class name, and helper method in the class are consistent to some extent.
Post the code:
Two helper, see clearly, they are different.
Version zf 1.10
Bootstrap.php
Class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {protected function _ initDoctype () {$this- > bootstrap ('view'); $view = $this- > getResource (' view'); $view- > doctype ('XHTML1_STRICT');} protected function _ initView () {$view = new Zend_View (); $view- > setEncoding (' UTF-8'); $view- > doctype ('XHTML1_STRICT') $view- > addHelperPath ('.. / application/views/helpers', 'My_View_Helper'); $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer (); Zend_Controller_Action_HelperBroker::addHelper ($viewRenderer); $viewRenderer- > setView ($view); return $view;}}
Application/views/helpers
Img.php:
Class Zend_View_Helper_Img extends Zend_View_Helper_Abstract {public function img () {return "this is an img";}}
TestHelper.php:
Class My_View_Helper_TestHelper extends Zend_View_Helper_Abstract {public function testHelper () {return "this is a TestHelper";}}
In action, use:
Additional content, add addHelperPath to initView, you can change it to load application. The path is configured in the way that the ini file configuration items are configured. As follows
Class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {protected function _ initDoctype () {$this- > bootstrap ('view'); $view = $this- > getResource (' view'); $view- > doctype ('XHTML1_STRICT');} protected function _ initView () {$view = new Zend_View (); $view- > setEncoding (' UTF-8'); $view- > doctype ('XHTML1_STRICT'); $options = $this- > getOptions (); $viewOptions = $options [' resources'] ['view'] [' helperPath'] If (is_array ($viewOptions)) {foreach ($viewOptions as $helperName = > $path) {$view- > addHelperPath ($path, $helperName);}} $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer (); Zend_Controller_Action_HelperBroker::addHelper ($viewRenderer); $viewRenderer- > setView ($view); return $view } [production] phpSettings.display_startup_errors = 1phpSettings.display_errors = 1includePaths.library = APPLICATION_PATH "/.. / library" bootstrap.path = APPLICATION_PATH "/ Bootstrap.php" bootstrap.class = "Bootstrap" appnamespace = "Application" resources.view [] = resources.view.helperPath.My_View_Helper = ".. / application/views/helpers" resources.frontController.controllerDirectory = APPLICATION_PATH "/ controllers" resources.frontController.params.displayExceptions = 1 [staging: production] [testing: production] phpSettings. Display_startup_errors = 1phpSettings.display_errors = 1 [development: production] phpSettings.display_startup_errors = 1phpSettings.display_errors = 1resources.frontController.params.displayExceptions = 1 are all the contents of the article "what are the considerations related to the Zend Framework Custom Helper Class" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 233
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.