php 无法在 codeigniter 中加载请求的文件错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17874060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:37:14  来源:igfitidea点击:

Unable to load the requested file error in codeigniter

phpimagecodeigniter

提问by user2621440

I am new to CodeIgniter. I am getting this problem.

我是 CodeIgniter 的新手。我遇到了这个问题。

Unable to load the requested file:
http://localhost/grf_new/index.php/reservation/details/34/.php

the code looks like this

代码看起来像这样

$this->load->view(base_url().index_page().'/reservation/details/'.$userid.'/', $data);

回答by Bora

Codeigniter Documentation:http://ellislab.com/codeigniter/user-guide/general/views.html

Codeigniter 文档:http : //ellislab.com/codeigniter/user-guide/general/views.html

Loading a View

加载视图

To load a particular view file you will use the following function:

要加载特定的视图文件,您将使用以下函数:

$this->load->view('viewfile', $yourdata);

Where viewfile is the name of your view file. Note: The .php file extension does not need to be specified unless you use something other than .php.

其中 viewfile 是您的视图文件的名称。注意: .php 文件扩展名不需要指定,除非您使用 .php 以外的其他文件。

Now, open the controller file you made earlier called blog.php, and replace the echo statement with the view loading function:

现在,打开您之前创建的名为 blog.php 的控制器文件,并将 echo 语句替换为视图加载函数:

<?php
class Reservation extends CI_Controller {

    function details($id)
    {
        $this->data['user_info'] = $this->user_model->getUser($id)->result();
        $this->load->view('userdetails', $this->data);
    }
}
?>

If you visit your site using the URL you did earlier you should see your new view. The URL was similar to this:

如果您使用之前所做的 URL 访问您的站点,您应该会看到您的新视图。该 URL 类似于以下内容:

example.com/reservation/details/34

回答by Sundar

Don't add base_url()

不要添加 base_url()

Load files using this

使用此加载文件

$this->load->view('test/test', $data);

create a file in view folder if your folder like this

如果您的文件夹是这样的,则在视图文件夹中创建一个文件

application/views

test/test.php

//---------------------

//If you want to read the URL use file_get_contents() function

回答by Xavier W.

This should work (doesnt test) :

这应该工作(不测试):

$this->load->view('reservation/details/'.$userid, $data);