當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。