“Unable to load the requested file”

2019-08-01 07:03发布

问题:

Using CodeIgniter 2.0.3 on XAMPP 1.7.7 I have code where I get the error as: Unable to load the requested file: home.php

The home.php code as follows stored in ./ci2/application/controllers:

class Home extends CI_Controller {

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

    function index()
    {
        $this->load->view('home');
    }

回答1:

While using it just notice:

  1. controller's name is home.php

  2. File named home.php must be present in ci/views

  3. Incase file extention in view folder is not php eg like its html. then load it using : $this->load->view('home.html');

  4. the function u need to call from outside must be public So make it: public function index() {... }

as u are calling the constructor for the class Home. Call it like:

class Home extends CI_Controller {

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

public function index()
{
    $this->load->view('home');
}

Now it will work !



回答2:

Your call to $this->load->view('home'); will be looking for home.php in /ci2/application/views/. That's the file it can't find.

I'm assuming you're calling http://myapp/index.php/home/ - that means it'll automatically call the index() method.



回答3:

class Home extends CI_Controller
{
    function __construct()
    {
        parent::__construct();   
    }
    function index()
    {
        $this->load->view('home');
    }   
}

Please check the name of the file you have created in application/views/, because otherwise the code is correct.