/** * Tesst setting and getting the file * * @access public * @return void */ public function testFile() { $view = new View(); $view->setFile('test'); // Assert without extension $this->assertSame('test', $view->getFile()); $this->assertSame('test', $view->getFile(false)); // Assert with extension $this->assertSame('test.php', $view->getFile(true)); }
/** * Begin the routing * * @access public * @return void */ public function init() { $coreViewPath = WP::applyFilters('wpmvc_core_views_path', $this->getCorePath() . '/Views/'); $appViewPath = WP::applyFilters('wpmvc_app_views_path', $this->getTemplatePath() . '/app/views/'); // Create a new view and set the default path as the current path $theHeader = new View($coreViewPath); $theBody = new View($appViewPath); $theFooter = new View($coreViewPath); // Set the header view $theHeader->setFile(WP::applyFilters('wpmvc_header_file', 'header')); $theHeader->setVar('app', $this); // Set the footer view $theFooter->setFile(WP::applyFilters('wpmvc_footer_file', 'footer')); $theFooter->setVar('app', $this); // If the front page is requested if (WP::isFrontPage() || WP::isHome()) { $theBody->setFile('home'); $theBody->setVar('app', $this); } else { // Retrieve the requested post type $postType = WP::getQueryVar('post_type'); if (WP::is404()) { // 404 view $theBody->setFile('404'); } elseif (WP::isSearch()) { // Search index $theBody->setFile('search/index'); } elseif (WP::isTax()) { // Taxonomy archive $taxonomy = WP::getQueryVar('taxonomy'); $theBody->setFile(sprintf('taxonomy/%s/index', $taxonomy)); } elseif (WP::isTag()) { // Tag archive $theBody->setFile('tag/index'); } elseif (WP::isCategory()) { // Category archive $theBody->setFile('category/index'); } elseif (WP::isPage()) { // Page view $theBody->setFile(WP::getCurrentPageName()); // If view file doesn't exist, fallback to the page.php view if (!$theBody->hasFile()) { $theBody->setFile('page'); } } elseif (WP::isPostTypeArchive()) { // Post type archive $theBody->setFile(sprintf('%s/index', $postType)); } elseif (WP::isSingle()) { // Retrieve the current requested post type (applies to pages, and post single and archive views) $postType = WP::getPostType(); // Post permalink $theBody->setFile(sprintf('%s/single', $postType)); } } // Apply the body file filter $theBody->setFile(WP::applyFilters('wpmvc_body_file', $theBody->getFile())); echo WP::applyFilters('wpmvc_header_output', $theHeader->output()); echo WP::applyFilters('wpmvc_body_output', $theBody->output()); echo WP::applyFilters('wpmvc_footer_output', $theFooter->output()); }