2

I have been working on a session validation for my login to make sure that a user is logged in to view pages. I keep getting this error:

Fatal error: Class 'MY_Staffcontroller' not found in /usr/local/var/www/CodeTest /ci/application/controllers/staff_c.php on line 3

My staff_c page looks like so :

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

class Staff_c extends MY_Staffcontroller {

    function homepage()
    {
        $data['main_content'] = 'homepage_view';
        $this->load->view('includes/template', $data);
    }
}

I have been reading same questions all over the place and they say the same thing pretty much...

Is your controller located in application/core?

Well yes it is. I can't seem to get passed this hump!

Controller image

This is the code within My_Staffcontroller.php:

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

class MY_staffcontroller extends CI_Controller {

    function __construct()
    {
        parent::__construct();

        $loggedin = $this->session->userdata('loggedin');
        if(!isset($loggedin) || $loggedin != TRUE);
        {
            die($this->load->view('denied'));
        }
    }
}

I know this is user error as this is only my second day with CodeIgniter but I can't seem to find proper workaround for this?

I have tried this tutorial and still nothing and also this

Even following this video has me stuck on the session part.

And I just can not get this to work.

Community
  • 1
  • 1
RaGe10940
  • 659
  • 2
  • 6
  • 20

1 Answers1

4

Remember Linux is case-sensative whereas Windows is case-insensative.

place you're MY_Staffcontroller inside application/core/MY_Controller.php file

Your MY_Controller.php file should look like this (minus all you're other functions, this is a minimal example)

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

class MY_Controller extends CI_Controller
{
   public function __construct() 
   {
       parent::__construct(); 
   }
}
class MY_Staffcontroller extends MY_Controller 
{
    public function __construct() 
    {
       parent::__construct();
    }
    public function sayHello()
    { 
        echo "Hello, I am a function within MY_Staffcontroller.php";
    }
}

Example

This will be located in /application/controllers directory Basically any protected and public functions located in either MY_Controller OR MY_Staffcontroller will be accessible from derived controllers that extend the extended controller. In this case it would be MY_Staffcontroller

class Public_Staff_Controller extends MY_Staffcontroller 
{
    public function __construct()
    {
        parent::__construct();
    }
    public function index()
    {
        $this->sayHello();
    }
}

/* end of file /application/core/MY_Controller.php */
Ryan
  • 14,392
  • 8
  • 62
  • 102
  • alright, I didn't get any errors this time (for once) I however didn't get anything period (just a blank page). I feel it is because of my die($this->load->view('invalid)); – RaGe10940 Feb 15 '13 at 03:52
  • I just edited my answer. Check it out. It is a simple example that will help you grasp the concept of this pattern. This is the best way to use CodeIgniter IMO – Ryan Feb 15 '13 at 03:56
  • I'm still working on this. Don't think I am not reading your edits. Your awesome, thank you. – RaGe10940 Feb 15 '13 at 03:59
  • @RaGe10940 Not a problem. It's why I'm here. – Ryan Feb 15 '13 at 04:00
  • Oh sorry for commenting late, this worked perfectly. I am using this system as my user authorization and role authorization. Thanks a lot! – RaGe10940 Feb 16 '13 at 00:03