简体   繁体   English

显示Codeigniter 404错误

[英]Codeigniter 404 error is shown

I am following the tutorial-Static pages, from codeigniter website. 我正在关注codeigniter网站上的静态教程页面。

  1. I extracted the codeignitor zip into my local server. 我将codeignitor zip解压缩到本地服务器中。
  2. Edited the line 编辑行

     $config['base_url']='http://localhost/'; 

in application /config/config.php 在应用程序/config/config.php中

  1. Created the file: application/controllers/pages.php to have following contents: 创建文件:application / controllers / pages.php具有以下内容:

     <?php class Pages extends CI_Controller { public function view($page = 'home') { if ( ! file_exists('/var/www/application/views/pages/'.$page.'.php')) { // Whoops, we don't have a page for that! show_404(); } $data['title'] = ucfirst($page); // Capitalize the first letter $this->load->view('templates/header', $data); $this->load->view('pages/'.$page, $data); $this->load->view('templates/footer', $data); } } 
  2. Created the file: application/views/templates/header.php with some HTML content. 创建了文件:application / views / templates / header.php,其中包含一些HTML内容。

  3. Created the file: application/views/templates/footer.php with some HTML content. 创建了文件:application / views / templates / footer.php,其中包含一些HTML内容。

Now, when I go to 现在,当我去

  localhost/index.php/pages/view/about

I expect the 'about' page, but 404 error is shown. 我希望看到“关于”页面,但显示404错误。

Why is that? 这是为什么?

please try following 请尝试关注

if (file_exists(APPPATH."views/pages/". $page. ".php")) {

   $this->load->view("pages/". $page);

} 

APPPATH = well self explanatory APPPATH =自我说明

I think the problem is here- 我认为问题出在这里

if ( ! file_exists('/var/www/application/views/pages/'.$page.'.php'))

You should also mention the name of your codeigniter folder as well! 您还应该提到您的codeigniter文件夹的名称!

Some webservers expect a question mark, like so: 一些网络服务器期望一个问号,例如:

localhost/index.php?/pages/view/about


Can you test this? 你能测试一下吗?

Instead of this 代替这个

$config['base_url']='http://localhost/'; 

Try 尝试

$config['base_url']='http://localhost/project_name/'; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM