Created
June 26, 2013 01:37
-
-
Save eminetto/5864071 to your computer and use it in GitHub Desktop.
Exemplo de ViewHelper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Application\View\Helper; | |
| use Zend\View\Helper\AbstractHelper; | |
| use Zend\ServiceManager\ServiceLocatorAwareInterface; | |
| use Zend\ServiceManager\ServiceLocatorInterface; | |
| /** | |
| * Retorna o recurso sendo acessado | |
| * | |
| * @category Application | |
| * @package View\Helper | |
| * @author Elton Minetto <eminetto@coderockr.com> | |
| */ | |
| class RecursoAtual 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() | |
| { | |
| $helperPluginManager = $this->serviceLocator; | |
| $serviceLocator = $helperPluginManager->getServiceLocator(); | |
| return $serviceLocator; | |
| } | |
| /** | |
| * Executa a lógica do helper | |
| * @return array | |
| */ | |
| public function __invoke() | |
| { | |
| $routeMatch = $this->getServiceLocator()->get('application')->getMvcEvent()->getRouteMatch(); | |
| $moduleName = $routeMatch->getParam('moduleUri'); | |
| $controllerName = $routeMatch->getParam('controller'); | |
| $actionName = $routeMatch->getParam('action'); | |
| $id = $routeMatch->getParam('id', 0); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment