dongqin1819 2013-02-15 03:35
浏览 64
已采纳

无法找到CodeIgniter'MY_'错误

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.

  • 写回答

1条回答 默认 最新

  • doupu1727 2013-02-15 03:43
    关注

    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 */
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退