Codeigniter-404页面中的路由未找到


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错误

如果在$this->load->view('templates/footer');之后使用exit;,则页面显示为空白页面。

我没有任何与支持相关的路线,其他所有方法都在起作用路线上有我遗漏的东西吗??

谢谢你的帮助。

判断标题,首先检查您的服务器是否使用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');
    }