【问题标题】:codeigniter 2: getting 404 error on default controllercodeigniter 2:在默认控制器上出现 404 错误
【发布时间】:2013-03-14 17:59:31
【问题描述】:

我这样设置默认控制器

$route['default_controller'] = "InterviewController";

这是 InterviewController 的代码

class InterviewController extends CI_Controller{
    private $em;

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

    public function index() {
        $commentsList = array();
        $commentsList['comments'] = $this->em->getRepository('Entities\Comment')->findPage(1, 10, 'DESC', $this->em->getRepository('Entities\Interview')->getLast()[0]->getId());
        $lastInterviewsAnons = array();
        $lastInterviewsAnons['lastInterviewsAnons'] = $this->em->getRepository('Entities\Interview')->getLast();
        $this->load->view('header');
        $this->load->view('navbar');
        $this->load->view('content', $lastInterviewsAnons);
        $this->load->view('addCommentPanel');
        $this->load->view('commentsList', $commentsList);
        $this->load->view('footer');
    }
}

在我的本地机器上一切正常,但在服务器上我得到 404 错误。我只能通过输入完整的 url 来访问这个控制器,比如http://mydomain.com/index.php/InterviewController。似乎路由文件中的指令不起作用。你有什么建议?

【问题讨论】:

  • 检查你的模组重写和你的文件名大小写。你的文件名应该是小写的,你的 URI 也是。
  • mod 重写已启用。我将文件名更改为小写。将路由规则更改为 $route['default_controller'] = "interviewcontroller";。反正我有 404
  • 请贴出与此路由相关的.htaccess文件内容
  • RewriteEngine on RewriteCond $1 !^(index\.php|img|robots\.txt|css|js|libraries/ckeditor|upload) addDefaultCharset UTF-8
  • 您确定将 routes.php 上传到服务器还是仍在寻找 welcome.php ? :P 重新检查所有命名约定。如果你的 mod 重写没有做奇怪的事情,它在你的配置文件或命名中。\

标签: php routing controller codeigniter-2


【解决方案1】:

请检查您的 htaccess 文件以获取重写代码。如果没问题,请尝试以下步骤。

1) 将类名改为

 class Interview extends CI_Controller

2) 文件名到 interview.php

3) 在 routes.php $route['default_controller'] = "interview";

【讨论】:

  • rewrite mod 已禁用。我按照你的建议改变了一切。 Goooood 那行不通。现在它就像在 codeigniter 演示中一样,它是受欢迎的默认控制器,但受欢迎的工作,我的控制器 - 没有
  • 还要检查 interview.php 文件是否在正确的位置(application/controllers 文件夹),并且所有从页眉到页脚的视图文件都在 application/views 文件夹中。我知道你可能把它保存在正确的位置,但只是重新检查..
  • 浏览器正在缓存 url。所以它再次加载了404。现在一切正常。谢谢,伙计们
猜你喜欢
  • 1970-01-01
  • 2011-11-29
  • 2020-11-28
  • 2017-04-17
  • 1970-01-01
  • 1970-01-01
  • 2019-01-05
  • 2015-11-10
  • 2015-11-04
相关资源
最近更新 更多