Plugins in ZF:
Plugins are heavily used in ZF. With plugins we can achieve extensibility and customization of the framework.
Plugins in ZF :
Components use Zend_Loader_PluginLoader to make use of plugins. Then the components will call the PluginLoader's load() method and pass the plugin's short name with it. The PluginLoader will then query each prefix path to see whether the class matching the short name exists. LIFO (Last In First Out) data structure is used to match those prefix paths.
The concept of prefix paths and overriding existing plugins helps us to understand many components ZF. Use of plugins are :
Zend_View: view helpers
Zend_Controller_Action: action helpers.
Zend_Form: elements, filters, validators, and decorators. .
Let's consider one example: Zend_View_Helper_FormButton. This view helper accepts three arguments, first is element name (element's DOM identifier), second is the value (button label), and the last one is optional array of attributes. After getting these arguments this helper generates the form input element in HTML.
Suppose you want the helper to generate a HTML button element; not a DOM identifier, instead of using the value for a CSS class selector; and you are not interestest in handling arbitrary attributes. We can get this by more than one ways. In both the cases, we would create view helper class that will implement the behavior which is actually needed ; the difference lies in how we would name and invoke them.
Posted on: April 28, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles