當前位置: 首頁>>代碼示例>>PHP>>正文


PHP MvcEvent::setController方法代碼示例

本文整理匯總了PHP中Zend\Mvc\MvcEvent::setController方法的典型用法代碼示例。如果您正苦於以下問題:PHP MvcEvent::setController方法的具體用法?PHP MvcEvent::setController怎麽用?PHP MvcEvent::setController使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Mvc\MvcEvent的用法示例。


在下文中一共展示了MvcEvent::setController方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onRoute

 /**
  * Global Route /module/controller/action
  * @param MvcEvent $e
  */
 public function onRoute(MvcEvent $e)
 {
     $matches = $e->getRouteMatch();
     $module = $matches->getParam('module');
     $controller = $matches->getParam('controller');
     if ($module && $controller && strpos($controller, '\\') === false) {
         $matches->setParam(self::ORIGINAL_CONTROLLER, $controller);
         $controllerLoader = $e->getApplication()->getServiceManager()->get('ControllerManager');
         $ctrlClass = $this->convertName($module) . '\\Controller\\';
         $ctrlClass .= $this->convertName($controller);
         $controller = $ctrlClass;
         $matches->setParam('controller', $controller);
         $ctrlClass .= 'Controller';
         if (!$controllerLoader->has($controller) && class_exists($ctrlClass)) {
             $controllerLoader->setInvokableClass($controller, $ctrlClass);
             $e->setController($controller);
             $e->setControllerClass($ctrlClass);
         }
     }
 }
開發者ID:cityware,項目名稱:city-mvc,代碼行數:24,代碼來源:GlobalRouteListenerController.php

示例2: test404ResponsePrepares404ViewModelWithControllerWhenAllowed

 public function test404ResponsePrepares404ViewModelWithControllerWhenAllowed()
 {
     $response = new Response();
     $event = new MvcEvent();
     $controller = 'some-or-other';
     $controllerClass = 'Some\\Controller\\OrOtherController';
     $event->setController($controller);
     $event->setControllerClass($controllerClass);
     foreach (array('setDisplayNotFoundReason', 'setDisplayExceptions') as $method) {
         foreach (array(true, false) as $allow) {
             $this->strategy->{$method}($allow);
             $response->setStatusCode(404);
             $event->setResult(null);
             $event->setResponse($response);
             $this->strategy->prepareNotFoundViewModel($event);
             $model = $event->getResult();
             $this->assertInstanceOf('Zend\\View\\Model\\ModelInterface', $model);
             $variables = $model->getVariables();
             if ($allow) {
                 $this->assertTrue(isset($variables['controller']));
                 $this->assertEquals($controller, $variables['controller']);
                 $this->assertTrue(isset($variables['controller_class']));
                 $this->assertEquals($controllerClass, $variables['controller_class']);
             } else {
                 $this->assertFalse(isset($variables['controller']));
                 $this->assertFalse(isset($variables['controller_class']));
             }
         }
     }
 }
開發者ID:razvansividra,項目名稱:pnlzf2-1,代碼行數:30,代碼來源:RouteNotFoundStrategyTest.php

示例3: marshalMiddlewareNotCallable

 /**
  * Marshal a middleware not callable exception event
  *
  * @param  string $type
  * @param  string $middlewareName
  * @param  MvcEvent $event
  * @param  Application $application
  * @param  \Exception $exception
  * @return mixed
  */
 protected function marshalMiddlewareNotCallable($type, $middlewareName, MvcEvent $event, Application $application, \Exception $exception = null)
 {
     $event->setName(MvcEvent::EVENT_DISPATCH_ERROR);
     $event->setError($type);
     $event->setController($middlewareName);
     $event->setControllerClass('Middleware not callable: ' . $middlewareName);
     if ($exception !== null) {
         $event->setParam('exception', $exception);
     }
     $events = $application->getEventManager();
     $results = $events->triggerEvent($event);
     $return = $results->last();
     if (!$return) {
         $return = $event->getResult();
     }
     return $return;
 }
開發者ID:kuisatz,項目名稱:ustalarMerkezi,代碼行數:27,代碼來源:MiddlewareListener.php

示例4: marshalBadControllerEvent

 /**
  * Marshal a bad controller exception event
  *
  * @param  string $controllerName
  * @param  MvcEvent $event
  * @param  Application $application
  * @param  \Throwable|\Exception $exception
  * @return mixed
  */
 protected function marshalBadControllerEvent($controllerName, MvcEvent $event, Application $application, $exception)
 {
     $event->setName(MvcEvent::EVENT_DISPATCH_ERROR);
     $event->setError($application::ERROR_EXCEPTION);
     $event->setController($controllerName);
     $event->setParam('exception', $exception);
     $events = $application->getEventManager();
     $results = $events->triggerEvent($event);
     $return = $results->last();
     if (!$return) {
         return $event->getResult();
     }
     return $return;
 }
開發者ID:zendframework,項目名稱:zend-mvc,代碼行數:23,代碼來源:DispatchListener.php


注:本文中的Zend\Mvc\MvcEvent::setController方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。