Skip to content

Instantly share code, notes, and snippets.

@Nully
Created July 3, 2012 07:38
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 Nully/3038292 to your computer and use it in GitHub Desktop.
Save Nully/3038292 to your computer and use it in GitHub Desktop.
ZF2のGlobalEventManagerの使い方例
<?php
namespace App;
use \Zend\ModuleManager\ModuleManager,
\Zend\Mvc\MvcEvent;
class Module
{
protected $config;
function init(ModuleManager $manager)
{
$events = $manager->events()->getSharedManager();
$self = $this; // クロージャのuseにて渡すため
$events->attach("application", MvcEvent::EVENT_BOOTSTRAP, function(MvcEvent $e) use ($self, $manager) {
$app = $e->getParam("application");
$config = $app->getConfiguration();
$self->setAppConfig($config); // アプリケーションの設定をモジュールに設定
$self->bootstrap($manager, $app);
});
}
function bootstrap($manager, $app)
{
// ここに初期化などを書く
}
// 設定を設置
function setAppConfig()
{
$this->config = $config;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment