Welcome Guest, Not a member yet? Register   Sign In
Can't get custom controllers to work..
#1

[eluser]Unknown[/eluser]
Hello CodeIgniters!

I'm new to the framework and can't seem to get the custom controllers to work..
So far I have a custom base controller:

application/core/my_controller.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends CI_Controller {

    private $header_data;
    private $footer_data;

public function __construct() {
        parent::__construct();
        
        $this->header_data["title"]    = WEBSITE_NAME;

        $this->include_manager->include_css("css/main.css");
  $this->include_manager->include_css("css/labels-in-forms.css");

  $this->include_manager->include_js("js/jquery-1.8.2.min.js");
  $this->include_manager->include_js("js/labels-in-forms.js");
    }

    public function set_title($title)
    {
     $this->header_data["title"]  = $title . " - " . WEBSITE_NAME;
    }

    public function load_header()
    {
  $this->header_data["includes"] = $this->include_manager->get_head_includes();

  $this->load->view('header', $this->header_data);
    }

    public function load_footer()
    {
     $this->footer_data["includes"] = $this->include_manager->get_foot_includes();

  $this->load->view('footer', $this->footer_data);
    }

}

It handles a bit of basic page stuff, as you can see.
Now, my real controller looks like this:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends MY_Controller {
function Welcome()
{
  parent::__construct();
}

function index()
{
  $data["current_root"] = 1;
  $data["menu_items"] = $this->menu_model->get_main_menu_items();

  $data["content"] = $this->db->get_where("page_content", array('page_id' => 1));

  $this->load_header();
  $this->load->view('templates/default', $data);
  $this->load_footer();
}
}

I have added the __autoload to config.php and made sure i'm running PHP 5+ (it's 5.2)
Code:
function __autoload($class)
{
    if (strpos($class, 'CI_') !== 0)
    {
        if (file_exists($file = APPPATH . 'core/' . $class . EXT))
        {
            include $file;
        }
        elseif (file_exists($file = APPPATH . 'libraries/' . $class . EXT))
        {
            include $file;
        }
    }
}

but still i get this nasty error message:

An Error Was Encountered
Unable to load the requested class: my_controller


What am i missing here, guys?
#2

[eluser]CroNiX[/eluser]
Filename should be in caps, like
/application/core/MY_Controller.php




Theme © iAndrew 2016 - Forum software by © MyBB