class CustomSawException extends Exception implements ServiceLocatorAwareInterface, SawExceptionInterface
{
protected $serviceLocator;
public function test(){
$this->serviceLocator->get('SomeThing');
}
/**
* Set service locator
*
* @param ServiceLocatorInterface $serviceLocator
*/
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
}
/**
* Get service locator
*
* @return ServiceLocatorInterface
*/
public function getServiceLocator()
{
return $this->serviceLocator;
}
为此抛出的异常是:
调用get()on null
我无法弄清楚它为什么会抛出异常?
ServiceLocatorAwareInterface
应该注入ServiceLocator
?
答案 0 :(得分:1)
ServiceLocator
应该注入new { pt.Id, pt.Title }
?
我不太确定,在最新版本的ZF2中,这个界面已被弃用。