Zend Framework 2的View Helper中使用Service Manager
程序员文章站
2022-03-24 14:33:36
...
<?php namespace Core\Helper; use Zend\View\Helper\AbstractHelper; use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorInterface; /** * View Helper */ class CustomHelper extends AbstractHelper implements ServiceLocatorAwareInterface { /** * Set the service locator. * * @param ServiceLocatorInterface $serviceLocator * @return CustomHelper */ public function setServiceLocator(ServiceLocatorInterface $serviceLocator) { $this->serviceLocator = $serviceLocator; return $this; } /** * Get the service locator. * * @return \Zend\ServiceManager\ServiceLocatorInterface */ public function getServiceLocator() { return $this->serviceLocator; } public function __invoke($in) { $config = $this->getServiceLocator()->getServiceLocator()->get('application')->getConfig(); return $config['URL'][$in]; } }
下一篇: 647. 回文子串