Skip to content

Instantly share code, notes, and snippets.

@robertbasic
Created July 23, 2011 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertbasic/1101201 to your computer and use it in GitHub Desktop.
Save robertbasic/1101201 to your computer and use it in GitHub Desktop.
ZF2 loading plugins and helpers
<?php
// telling ZF where an action helper is
class Bootstrap extends Application\Bootstrap {
public function _initActionHelpers()
{
Zend\Loader\PluginClassLoader::addStaticMap(array('loggedinuser' => 'Planet\Controller\Helper\LoggedInUser'));
}
// registering FC plugins can be done like this
// or simply add resources.frontcontroller.plugins.admin = "PPN\Plugin\AdminContext" to application.ini
public function _initFcPlugins()
{
$this->bootstrap('FrontController');
$fc = $this->getResource('FrontController');
$plugin = new PPN\Plugin\AdminContext();
$fc->registerPlugin($plugin);
}
<?php
class IndexController extends Action
{
public function init()
{
// some AHs are pre-aliased, see Zend\Controller\Action\HelperLoader
$this->fm = $this->broker('flashmessenger');
// accessing an AH which was aliased in the Bootstrap
$this->loggedInUser = $this->broker('loggedinuser');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment