Zend\Mvc\View\Http\InjectTemplateListener::injectTemplate PHP Метод

injectTemplate() публичный Метод

Template is derived from the controller found in the route match, and, optionally, the action, if present.
public injectTemplate ( MvcEvent $e ) : void
$e Zend\Mvc\MvcEvent
Результат void
    public function injectTemplate(MvcEvent $e)
    {
        $model = $e->getResult();
        if (!$model instanceof ViewModel) {
            return;
        }
        $template = $model->getTemplate();
        if (!empty($template)) {
            return;
        }
        $routeMatch = $e->getRouteMatch();
        if ($preferRouteMatchController = $routeMatch->getParam('prefer_route_match_controller', false)) {
            $this->setPreferRouteMatchController($preferRouteMatchController);
        }
        $controller = $e->getTarget();
        if (is_object($controller)) {
            $controller = get_class($controller);
        }
        $routeMatchController = $routeMatch->getParam('controller', '');
        if (!$controller || $this->preferRouteMatchController && $routeMatchController) {
            $controller = $routeMatchController;
        }
        $template = $this->mapController($controller);
        $action = $routeMatch->getParam('action');
        if (null !== $action) {
            $template .= '/' . $this->inflectName($action);
        }
        $model->setTemplate($template);
    }

Usage Example

Пример #1
0
 /**
  * Inject a template into the view model, if none present
  *
  * Template is derived from the controller found in the route match, and,
  * optionally, the action, if present.
  *
  * @param  MvcEvent $e
  * @return void
  */
 public function injectTemplate(MvcEvent $e)
 {
     $routeMatch = $e->getRouteMatch();
     $controller = $e->getTarget();
     if (is_object($controller)) {
         $controller = get_class($controller);
     }
     if (!$controller) {
         $controller = $routeMatch->getParam('controller', '');
     }
     if (strpos($controller, 'Ctrl\\Module') !== 0) {
         return;
     }
     parent::injectTemplate($e);
 }
All Usage Examples Of Zend\Mvc\View\Http\InjectTemplateListener::injectTemplate