首页 > 代码库 > Zend Framework 2 获取 Service Manager

Zend Framework 2 获取 Service Manager

在学习zend framework的时候很多的问题只能看源代码,为了加深自己的理解,记录下来平时用到的方法:

1在控制器里


$serviceLocator = $this->getServiceLocator();


2在Module.php里


namespace ModuleName;
                                                
use Zend\Mvc\MvcEvent;
                                                
class Module
{
    public function onBootstrap(MvcEvent $e)
    {
        $serviceLocator = $e->getApplication()->getServiceManager();
    }

}


3在控制器Plugin
$serviceLocator = $this->getController()->getServiceLocator();

Zend Framework 2 获取 Service Manager