Zend framework2 访问视图帮助程序中的服务定位器

Zend framework2 访问视图帮助程序中的服务定位器,zend-framework2,view-helpers,service-locator,Zend Framework2,View Helpers,Service Locator,我无法访问自定义视图帮助程序中的服务定位器。这是我的密码: <?php namespace Sam\View\Helper; use Zend\View\Helper\AbstractHelper; use Zend\ServiceManager\ServiceLocatorAwareTrait; use Zend\ServiceManager\ServiceLocatorAwareInterface; class Authenticat

我无法访问自定义视图帮助程序中的服务定位器。这是我的密码:

    <?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;
        }
    }

根据注释,如果要使用服务定位器特性,则需要类中的
使用ServiceLocatorAwareTit
行。您当前拥有的应该会给您一个错误,因为您正在实现的
ServiceLocatorAware
接口定义的方法缺失。

这是帮助程序的完整代码吗?看起来您在类中缺少了一行
使用ServiceLocatorIt
。是的,这就解决了问题。谢谢。你应该回答这个问题。