我是CodeIgniter的新手。我遇到了这个问题。
Unable to load the requested file:
http://localhost/grf_new/index.php/reservation/details/34/.php
代码看起来像这样
$this->load->view(base_url().index_page().'/reservation/details/'.$userid.'/', $data);
答案 0 :(得分:3)
Codeigniter文档: http://ellislab.com/codeigniter/user-guide/general/views.html
要加载特定的视图文件,您将使用以下函数:
$this->load->view('viewfile', $yourdata);
其中viewfile是视图文件的名称。注意:除非使用.php以外的其他内容,否则不需要指定.php文件扩展名。
现在,打开您之前创建的名为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);
}
}
?>
如果您使用之前执行的网址访问您的网站,则应该会看到新视图。网址与此类似:
example.com/reservation/details/34
答案 1 :(得分:2)
不要添加base_url()
使用此
加载文件$this->load->view('test/test', $data);
如果你的文件夹是
,请在视图文件夹中创建一个文件application/views
test/test.php
//---------------------
//If you want to read the URL use file_get_contents() function
答案 2 :(得分:1)
这应该有效(不测试):
$this->load->view('reservation/details/'.$userid, $data);