setController() public method

Set controller name
public setController ( string $name ) : MvcEvent
$name string
return MvcEvent
 /**
  * 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);
         }
     }
 }
 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']));
             }
         }
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }