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

NorthClick Blog: Tips for creating a small but solid newsletter-system

Josh Holmes' Blog: ASP.NET and PHP On IIS Together

Gonzalo Ayuso's Blog: Real time monitoring PHP applications with websockets and node.js

PHPBuilder.com: Using Ajax with PHP to Create an Interactive Web Page

Developer Drive: Introducing Laravel, part 2


Community Events





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


conference code bugfix release list laravel voicesoftheelephpant threedevsandamaybe introduction deployment zendserver symfony podcast community series api tips interview language framework

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