Welcome Guest, Not a member yet? Register   Sign In
Issue with views and custom theme engine.
#1

[eluser]sneddo[/eluser]
I have been working on themeing for my CMS App and I am having asome problems that I am unable to sort. I will paste the code of my Template clas first then explain the problem.

Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 4.3.2 or newer
*
* @package        CodeIgniter
* @author        Rick Ellis
* @copyright    Copyright (c) 2006, EllisLab, Inc.
* @license        http://www.codeignitor.com/user_guide/license.html
* @link        http://www.codeigniter.com
* @since        Version 1.0
* @filesource
*/

// ------------------------------------------------------------------------

/**
* CodeIgniter Layout Class
*
* First stab at a theme class
*
* @package            CodeIgniter
* @subpackage        Libraries
* @category        Libraries
* @author            David McLean
* @link
*/
class Template {
    var $_styles = array(); //build an array of style sheets
    var $_scripts = array(); // build an array of scripts
    //var _template = '';
    var $_layout = 'layout'; // the layout that should be used (default to 'layout')
    var $_theme = ''; // the theme that should be used.
    var $_themeOverride = FALSE; // use in admin area to override the frontend theme.
    var $CI;
    var $data;
    var $themeDir;
    var $layoutDir;
    
    function __construct() {
        // Find out what theme should be used - either active theme of override theme.
        if(!$this->_themeOverride){
            $this->CI =& get_instance();
            $this->CI->load->database();
            $query = $this->CI->db->get_where('options', array('option_name' => 'theme'));
            if ($query->num_rows() > 0){
                $row = $query->row();
                $_theme = $row->option_value;
            }
        }
        // get the theme directory path
        $this->themeDir = APPPATH.'themes/'.$_theme;
        //The layout path = :
        $this->layoutDir = $this->themeDir.'/views/layouts/';
    }
        
        
    function setTheme($theme){
        $this->_theme = $theme;
        $this->_themeOverride = TRUE;
    }
    function setLayout($layout){
        $this->_layout = $layout;
    }
    function addStyleSheet($cssFileName, $last=FALSE){
        // How many style sheets have been added so far?
        $cssCount = count($this->_styles);
        $cssFileLink = $this->themeDir.'/'.$cssFileName.'.css';
        // add stylesheet to the File sheet array.
        if($cssCount==0){
            $this->_styles[0] = '<link href="'.$cssFileLink.'" type="text/css" rel="stylesheet">';
        } else {
            $this->_styles[$cssCount + 1] = '<link href="'.$cssFileLink.'" type="text/css" rel="stylesheet">';
        }
        // have a global location for stylesheet files - check this location if file not found in theme folder
        // Add at later date.
    }
    function addScript($jsFileName, $last=FALSE){
        // add js file to the js file array.
        $jsCount = count($this->_scripts);
        $jsFileLink = $this->themeDir.'/'.$jsFileName.'.js';
        // add stylesheet to the File sheet array.
        if($jsCount==0){
            $this->_scripts[0] = '[removed]';
        } else {
            $this->_styles[$cssCount + 1] = '[removed]';
        }
        // have a global location for js files - check this location if file not found in theme folder
        // Add at Later Date.
    }
    function show($info){
        //pin it all together...
        //create the data array.
        $this->data['styles'] = $this->_styles;
        $this->data['scripts'] = $this->_scripts;
        $this->data['data'] = $info;
        //$this->data->theme_view_folder = '../themes/'.$this->_theme.'/views/';
        //And the location of the theme layout file is:
        $LayoutFile = $this->layoutDir.$this->_layout;
        //call the layout with data
        $this->CI->load->view($LayoutFile, $this->data);
        //after finished pinning it all together reset the vars.
        _clearVars();
    }
    function _clearVars(){
        $this->_scripts = array();
        $this->_styles = array();
        $this->_themeOverride = FALSE;
    }

}

When I run this I get the following error:


An Error Was Encountered

Quote:Unable to load the requested file: application/themes/default_theme/views/layouts/layout.php

The path to my layout is correct, I think it must have something to do with the fact it is outside the views folder, how can I get the application to run view files from within my themes folder?

regards,
#2

[eluser]sneddo[/eluser]
I sorted my problem, it was actaully a rather simple fix once you know how. I got the in I needed from the following post:

http://ellislab.com/forums/viewreply/627749/

regards.




Theme © iAndrew 2016 - Forum software by © MyBB