0
我无法访问我的定制视图助手中的服务定位器。这里是我的代码:在视图助手中访问服务定位器
<?php
namespace Sam\View\Helper;
use Zend\View\Helper\AbstractHelper;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
class Authenticated extends AbstractHelper imeplements ServiceLocatorAwareInterface
{
protected $authservice;
public function __invoke()
{
if (!$this->getAuthService()->hasIdentity()){
return false;
}
return true;
}
public function getAuthService()
{
if (! $this->authservice) {
$this->authservice = $this->getServiceLocator()->get('AuthService');
}
return $this->authservice;
}
}
这是助手的完整代码吗?看起来你错过了在课堂上使用ServiceLocatorAwareTrait行。 – 2014-08-28 15:47:45
是的,解决了它。谢谢。 – jkushner 2014-08-28 15:51:29
你应该做出答案。 – jkushner 2014-08-28 15:51:44