• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dont get js and css from MY_Controller (as in wiki)

What do I have to do more to get stylesheet-data in my page?
The folderpath seems to be right. Who is working with the MY_Controller from codeigniter github wiki and could give me a hint.


* This library extends the default controller and adds some useful extra features.
* Features:
*         1. Enables the usage of master page/templates.
*         2. Can add css and javascript files.
*         3. Uses the _output method for controling the controllers output.
*         4. Can load relative content with in the form of modules (views)
class MY_Controller extends CI_Controller {
    /* Output control constants */
    const OUTPUT_TEMPLATE = 10;
    const OUTPUT_NORMAL = 11;
    /* Private properties */

    //the default template
    private $template_view = 'default';
    //the default public folder this means that content inside this folder will be accessed directly
    //without using the routing.
    //Note!!! This folder must be enabled in the .htaccess file.
    private $public_folder = 'assets/';
    //the default location for the templates inside the views folder this means (views/templates/)
    private $template_folder = 'templates/';
    //the default css location for the css files inside the $public_folder("public/" by default) (public/css/)
    private $css_folder = 'css/';
    //the default js location for the css files inside the $public_folder("public/" by default) (public/js/)
    private $js_folder = 'js/';
    //Inline scripting (Javascript)
    private $inline_scripting = '';

    private $modules = array(); //An array that contains the modules output.

    private $charset = 'utf8'; //The page charset

    private $title = 'Testpage'; //The page Title
    //Media files and data
    private $media = array('css'=>array(),
                             //meta tags
                            'meta'=>array(  'viewport'      =>  'width=device-width, initial-scale=1.0',
                                            'robot'         =>  'noindex,nofollow',
                                            'description'   =>  'just a testpage'
                             //RDF are 3rd genreration meta tags
    //The requested controller
    protected $controller = '';
    //The requested method to be called
    protected $method        = '';
    private $_output_data = array();

     * The MY_Controller constructor method.
    function __construct(){
        //Initializing the controller
        //Get the default charset from the config file.
        $this->charset = $this->config->item('charset');

        //Set the default mode to use a template view

        //Passing as properties the controller and the method that should be called.
        $this->controller = $this->uri->rsegment(1);
        $this->method      = $this->uri->rsegment(2);
     * CodeIgniter magic method that controls the output of a controller.
     * You can't call it directly.
     * @see http://codeigniter.com/user_guide/general/controllers.html#output
     * @final this method cannot be overloaded
     * @param string $output the controller output
     * @return void
    final function _output($output){
            //Use the template
            case self::OUTPUT_TEMPLATE:
                $data = array(    'meta'=>$this->media['meta'],
                //Merge the data arrays
                $data = array_merge($data, $this->_output_data);
                //Load the final output
                $out = $this->load->view($this->template_folder . $this->template_view, $data, TRUE);
                //The End
                echo $out;
            //or just echo output.
            case self::OUTPUT_NORMAL:
                echo $output;
     * Adds a CSS file into the template.
     * @access protected
     * @param string $file a css file located inside the public/js/ folder or an url.
     * @param boolean $custom_url Default FALSE. A flag to determine if the given $file is an url or just a file insite the public/js/ folder.
     * @return bool
    public function _add_css_file($file, $custom_url=false){            
            $filepath = $this->public_folder . $this->css_folder . str_replace('.css','',$file) . ".css";

                show_error('Cannot locate css file: <tt><a href="'.$filepath.'">'.$filepath.'</a></tt>');
                return false;
            $filepath = base_url() . $filepath;
            $filepath = $file;

        if(array_search($filepath, $this->media['css']) === false)
            $this->media['css'][] = $filepath;
        else return false;
        return true;

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.