Beispiel #1
0
 public function dispatch()
 {
     $requestModule = $this->request->module();
     $requestController = $this->request->controller();
     $requestAction = $this->request->action();
     $controllerName = $this->buildControllerName($requestController, $requestModule);
     if (!class_exists($controllerName)) {
         throw new \Rapid\Dispatcher\Exception('Controller not found: ' . $controllerName);
     }
     /**
      * @var \Rapid\Controller
      */
     $controller = new $controllerName($this, $this->request);
     $action = $this->processActionName($requestAction);
     if (!method_exists($controller, $action)) {
         throw new \Rapid\Dispatcher\Exception('Action not found');
     }
     $actionView = new \Rapid\View();
     $actionView->setFile($this->viewFile($requestModule, $requestController, $requestAction));
     $controller->setView($actionView);
     $controller->preDispatch();
     $output = $controller->process($action);
     $controller->postDispatch();
     if ($controller->useLayout()) {
         $layout = new \Rapid\View();
         $layout->setFile($this->layoutFile($controller->layout()));
         $layout->setVariables((array) $controller->layoutVariables());
         $layout->setVariable('content', $output);
         $output = $layout->render();
     }
     echo $output;
 }
Beispiel #2
0
 public function testController()
 {
     $this->assertEquals(null, $this->request->controller(), 'Controller is not null');
     $this->request->setController('my');
     $this->assertEquals('my', $this->request->controller(), 'Controller is not "my"');
 }