Error Class Controller not found in CodeIgniter

前端 未结 3 755
离开以前
离开以前 2021-01-21 09:14

Hello, I am getting Controller not found error in CodeIgniter. This is my Controller code



        
相关标签:
3条回答
  • 2021-01-21 09:44

    As of CodeIgniter 2.x CI_ prefix is added to all core classes. Check the Change Log.

    Added CI_ Prefix to all core classes.

    For CodeIgniter 2.x

    <?php
    
    if (!defined('BASEPATH'))
        exit('No direct script access allowed');
    
    class HelloWorld extends CI_Controller
    {
    
        function __construct()
        {
            parent::__construct();
        }
    
        function index()
        {
            $this->load->view('index_view');
        }
    
        function hello()
        {
            $this->load->view('hello_view');
        }
    
    }
    

    For CodeIgniter 1.x

    <?php
    
    if (!defined('BASEPATH'))
        exit('No direct script access allowed');
    
    class HelloWorld extends Controller
    {
    
        function HelloWorld()
        {
            parent::Controller();
        }
    
        function index()
        {
            $this->load->view('index_view');
        }
    
        function hello()
        {
            $this->load->view('hello_view');
        }
    
    }
    

    Hope this helps you. Thanks!!

    0 讨论(0)
  • 2021-01-21 09:45

    i faced the same problem as you, and i solved it as simple as possible just by replacing the word Controller in the line of extending parent class by CI_Controller and it's work probably and here is the solution in your code

    <?php
    
    class HelloWorld extends CI_Controller{
    
       function HelloWorld() {
        parent::Controller();
       }
    
      function index() {
        $this->load->view('index_view');
      }
    
      function hello() {
        $this->load->view('hello_view');
      }
    
    }
    ?>
    

    and your code will execute

    0 讨论(0)
  • 2021-01-21 10:01

    Make sure your controller extends the parent controller class and also check your file name .

    <?
         class Helloworld extends CI_Controller {
    
                function index()
                {
                       $this->load->view('index_view');    
                }
    
                    function hello(){
                    $this->load->view('hello_view'); 
                    }
    
            }
            ?>
    
    0 讨论(0)
提交回复
热议问题