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

IBM developerWorks: Building the DB2 Health Monitor Sample Application for PHP (Part 2)

CodeIgniter Blog: CodeIgniter Community Voice - Generating PDF files using CodeIgniter

SitePoint PHP Blog: Understanding Drupal's EntityFieldQuery

Thomas Weinert: Carica Chip 101 - Controlling An LED With PHP

PHPBuilder.com: PHP Filters: An Important Security Feature


Community Events

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


voicesoftheelephpant version laravel library opinion laravel5 video api interview example language community release framework php7 podcast unittest series introduction list

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