[英]Routes in Codeigniter - 404 Page Not Found
谁能告诉我,问题出在哪里??
这是我的控制器
class Support extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('support_model');
$urlarray = array("index","delete");
if(!in_array($this->uri->segment(2),$urlarray)){
$this->viewticket($this->uri->segment(2));
}
}
public function viewticket($id){
if(!empty($id)){
$this->load->view('templates/logged_header');
$this->load->view('support/view');
$this->load->view('templates/footer');
}
}
}
这是我的routes.php
$route['default_controller'] = "welcome";
$route['benefits'] = 'welcome/benefits';
$route['faqs'] = 'welcome/faqs';
$route['distributors'] = 'welcome/distributors';
$route['contact'] = 'welcome/contact';
$route['purchase'] = 'welcome/purchase';
//login routes
$route['login'] = 'login/index';
$route['logout'] = 'login/logout';
$route['404_override'] = '';
localhost/ciproj/support/hello-world
给我404 Page Not Found
错误
如果我使用exit;
在$this->load->view('templates/footer');
,页面显示空白页。
我在与支持相关的路线中没有任何内容,并且所有其他方法都在起作用我在路线中遗漏了什么吗?
谢谢您的帮助。
判断标题,首先检查您的服务器是否使用CGI/FastCGI
运行 PHP(您可以简单地通过phpinfo()
检查)。
如果是这样,请在config.php
更改以下内容:
$config['uri_protocol'] = "REQUEST_URI";
回到主题,你可以通过在你的routes.php
文件中使用下面的单行路由来实现:
$route['support/(?!index)(?!delete)(:any)'] = "support/viewticket/$1";
并从您的__construct
方法中删除这些行:
$urlarray = array("index","delete");
if(!in_array($this->uri->segment(2),$urlarray)){
$this->viewticket($this->uri->segment(2));
}
让我知道它是如何工作的。
由于上面的答案对我不起作用,我只是在我的 default_controller 中添加了这个函数,它起作用了。
public function __construct() {
parent::__construct();
$this->load->helper('url');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.