News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Master Zend Framework:
Accessing ServiceManager Services in Controller Plugins
July 31, 2014 @ 09:43:49

Matthew Setter has posted another new tutorial to his Master Zend Framework site today showing you how to access ServiceManager services in controller plugins. Controller plugins are a Zend Framework feature that allows certain events to trigger the plugin code during the lifetime of the controller.

I've seen some questions on Google+ and StackOverflow of late, regarding how to get access to the Zend Framework 2 database adapter, along with other ServiceManager-defined services, in a custom controller plugin. This type of setup can come in handy for a number of situations. You may want to access services such as caching, logging or databases and want to provide a simple interface for doing so. People seem really interested in how to do it, but how to get access to services from the ServiceManager doesn't seem to be as clear as it could be. Gladly, there's not much involved in actually doing it.

He shows you how to create a plugin for an existing module, creating the two needed classes and adding a new function to configure it. He starts with the plugin factory that can be used to generate an instance of the plugin. Next is the plugin class itself that extends the abstract plugin and controller plugin classes. The required database adapter is injected into it via a constructor injection. Finally, in the Module.php configuration, he creates a "getControllerPluginConfig" method that registers the new plugin and points to its class. A screencast is also provided showing the active development of the code.

0 comments voice your opinion now!
servicemanager plugin controller tutorial access zendframework2

Link: http://www.masterzendframework.com/servicemanager/accessing-servicemanager-services-controller-plugins

blog comments powered by Disqus

Similar Posts

Abhinav Singh's Blog: Setting Nginx, PHP Fastcgi and XCache on a new Ubuntu

Michael Girouard's Blog: Rolling Your Own MVC: The View

Rob Allen's Blog: A list of ZF2 Events

Community News: PHP Tutorial Site - GoodPHPTutorials.com

Andy Bakun's Blog: Race Conditions with Ajax and PHP Sessions


Community Events





Don't see your event here?
Let us know!


series list podcast introduction bugfix interview community opinion framework install release api package voicesoftheelephpant tips deployment language laravel library symfony

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework