/**
  * Initialize the controller.
  *
  * This will set up default model and view classes.
  *
  * @return  $this  Method allows chiaining
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function initialize()
 {
     // Get the input
     /* @type Input $input */
     $input = $this->getContainer()->get('app')->input;
     // Get some data from the request
     $viewName = $input->getWord('view', $this->defaultView);
     $viewFormat = $input->getWord('format', 'html');
     $layoutName = $input->getCmd('layout', $this->defaultLayout);
     if (!$viewName) {
         $parts = explode('\\', get_class($this));
         $viewName = strtolower($parts[count($parts) - 1]);
     }
     $base = '\\App\\' . $this->app;
     $viewClass = $base . '\\View\\' . ucfirst($viewName) . '\\' . ucfirst($viewName) . ucfirst($viewFormat) . 'View';
     $modelClass = $base . '\\Model\\' . ucfirst($viewName) . 'Model';
     // If a model doesn't exist for our view, revert to the default model
     if (!class_exists($modelClass)) {
         $modelClass = $base . '\\Model\\DefaultModel';
         // If there still isn't a class, panic.
         if (!class_exists($modelClass)) {
             throw new \RuntimeException(sprintf('No model found for view %s or a default model for %s', $viewName, $this->app));
         }
     }
     // Make sure the view class exists, otherwise revert to the default
     if (!class_exists($viewClass)) {
         $viewClass = '\\JTracker\\View\\TrackerDefaultView';
     }
     // Register the templates paths for the view
     $paths = array();
     $sub = 'php' == $this->getContainer()->get('app')->get('renderer.type') ? '/php' : '';
     $path = JPATH_TEMPLATES . $sub . '/' . strtolower($this->app);
     if (is_dir($path)) {
         $paths[] = $path;
     }
     // @$this->model = $this->getContainer()->buildObject($modelClass);
     $this->model = new $modelClass($this->getContainer()->get('db'), $this->getContainer()->get('app')->input);
     // Create the view
     /* @type AbstractTrackerHtmlView $view */
     $this->view = new $viewClass($this->model, $this->fetchRenderer($paths));
     $this->view->setLayout($viewName . '.' . $layoutName);
     return $this;
 }
Esempio n. 2
0
 /**
  * Tests the setLayout method.
  *
  * @return  void
  *
  * @covers  Joomla\View\AbstractHtmlView::setLayout
  * @since   1.0
  */
 public function testSetLayout()
 {
     $result = $this->instance->setLayout('fringe/division');
     $this->assertAttributeSame('fringe/division', 'layout', $this->instance);
     $this->assertSame($this->instance, $result);
 }