当前位置: 首页>>代码示例>>PHP>>正文


PHP MvcEvent::getController方法代码示例

本文整理汇总了PHP中Zend\Mvc\MvcEvent::getController方法的典型用法代码示例。如果您正苦于以下问题:PHP MvcEvent::getController方法的具体用法?PHP MvcEvent::getController怎么用?PHP MvcEvent::getController使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Mvc\MvcEvent的用法示例。


在下文中一共展示了MvcEvent::getController方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handleError

 /**
  *
  */
 public function handleError(MvcEvent $event)
 {
     $controller = $event->getController();
     $error = $event->getParam('error');
     $exception = $event->getParam('exception');
     $message = sprintf('Error dispatching controller "%s". Error was: "%s"', $controller, $error);
     if ($exception instanceof \Exception) {
         $message .= ', Exception(' . $exception->getMessage() . '): ' . $exception->getTraceAsString();
     }
     error_log($message);
 }
开发者ID:mafkes,项目名称:socialNetwork,代码行数:14,代码来源:Module.php

示例2: injectController

 /**
  * Inject the controller and controller class into the model
  *
  * If either $displayExceptions or $displayNotFoundReason are enabled,
  * injects the controllerClass from the MvcEvent. It checks to see if a
  * controller is present in the MvcEvent, and, if not, grabs it from
  * the route match if present; if a controller is found, it injects it into
  * the model.
  *
  * @param  ViewModel $model
  * @param  MvcEvent $e
  * @return void
  */
 protected function injectController($model, $e)
 {
     if (!$this->displayExceptions() && !$this->displayNotFoundReason()) {
         return;
     }
     $controller = $e->getController();
     if (empty($controller)) {
         $routeMatch = $e->getRouteMatch();
         if (empty($routeMatch)) {
             return;
         }
         $controller = $routeMatch->getParam('controller', false);
         if (!$controller) {
             return;
         }
     }
     $controllerClass = $e->getControllerClass();
     $model->setVariable('controller', $controller);
     $model->setVariable('controller_class', $controllerClass);
 }
开发者ID:navassouza,项目名称:zf2,代码行数:33,代码来源:RouteNotFoundStrategy.php

示例3: onDispatch

 /**
  * General dispatch listener
  *
  * @param \Zend\Mvc\MvcEvent $event
  */
 public function onDispatch(MvcEvent $event)
 {
     if ($this->response) {
         $event->stopPropagation();
         return $this->response;
     }
     $routeMatch = $event->getRouteMatch();
     $sm = $event->getApplication()->getServiceManager();
     // Set current timezone, when first get
     $sm->get('Timezone');
     if ($routeMatch) {
         $locale = $routeMatch->getParam('locale');
     }
     if (!$locale) {
         $request = $event->getRequest();
         if ($request instanceof HttpRequest) {
             $header = $request->getHeader('Accept-Language');
             if ($header) {
                 $availables = null;
                 $controller = $event->getController();
                 if ($controller instanceof LocaleSelectorInterface) {
                     $availables = $controller->getAvailableLocales();
                 }
                 $locale = $sm->get('Locale')->acceptFromHttp($header->getFieldValue(), $availables);
             }
         }
     }
     if ($locale) {
         $sm->get('Locale')->setCurrent($locale);
     }
 }
开发者ID:gridguyz,项目名称:core,代码行数:36,代码来源:Module.php

示例4: detectError

 public function detectError(MvcEvent $event)
 {
     $result = $event->getResult();
     if ($result instanceof ResponseInterface) {
         // Already have a response as the result
         return;
     }
     $error = $event->getError();
     $ex = $event->getParam('exception');
     switch ($error) {
         case Application::ERROR_CONTROLLER_NOT_FOUND:
             $message = ucfirst($event->getControllerClass());
             $ex = new RdnException\RuntimeException($message, 500, $ex);
             break;
         case Application::ERROR_CONTROLLER_INVALID:
             $message = $event->getController() . ' is not dispatchable';
             $ex = new RdnException\RuntimeException($message, 500, $ex);
             break;
         case Application::ERROR_ROUTER_NO_MATCH:
             $message = 'Request did not match any routes.';
             $ex = new RdnException\NotFoundException($message, 404, $ex);
             break;
     }
     if (isset($message)) {
         if ($ex->getCode() == 500) {
             $event->setError(Application::ERROR_EXCEPTION);
         }
         $event->setParam('exception', $ex);
     }
 }
开发者ID:radnan,项目名称:rdn-exception,代码行数:30,代码来源:ExceptionStrategy.php


注:本文中的Zend\Mvc\MvcEvent::getController方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。