/** * Get and/or set the View * * This method declares the View to be used by the Slim application. * If the argument is a string, Slim will instantiate a new object * of the same class. If the argument is an instance of View or a subclass * of View, Slim will use the argument as the View. * * If a View already exists and this method is called to create a * new View, data already set in the existing View will be * transferred to the new View. * * @param string|\Slim\View $viewClass The name or instance of a \Slim\View subclass * @return \Slim\View */ public function view($viewClass = null) { if (!is_null($viewClass)) { $existingData = is_null($this->view) ? array() : $this->view->getData(); if ($viewClass instanceof \Slim\View) { $this->view = $viewClass; } else { $this->view = new $viewClass(); } $this->view->appendData($existingData); $this->view->setTemplatesDirectory($this->config('templates.path')); } return $this->view; }