【发布时间】: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