예제 #1
0
 /**
  * Automatically locates the ViewModel for the configured template, unless a response has already been generated.
  * 
  * @access  public
  * @return  Response
  */
 public function after($response)
 {
     // If a response has been provided, just go with it
     if (!is_null($response)) {
         return $response;
     }
     if ($this->status == 404) {
         return $this->show404();
     }
     // Get the model - this will have previously been found
     if (is_null($this->model)) {
         $this->model = \CMF::currentModel();
     }
     if (!isset($this->template)) {
         // Try and find the template from the CMF...
         $this->template = \CMF::$template;
     }
     if (is_null($this->template)) {
         return $this->show404();
     }
     // Determine whether the ViewModel class exists...
     if ($viewClass = \CMF::hasViewModel($this->template)) {
         $viewModel = new $viewClass('view', false, $this->template);
         $this->bindData($viewModel);
         return \Response::forge($viewModel, $this->status, $this->headers);
     }
     try {
         $viewClass = ucfirst(\CMF::$module) . '\\View_Base';
         if (!class_exists($viewClass)) {
             $viewClass = '\\View_Base';
         }
         $viewModel = new $viewClass('view', false, $this->template);
         $this->bindData($viewModel);
         return \Response::forge($viewModel, $this->status, $this->headers);
     } catch (\Exception $e) {
         return $this->show404("The template '" . $this->template . "' couldn't be found!");
     }
 }