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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18166496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:05:00  来源:igfitidea点击:

Routes in Codeigniter - 404 Page Not Found

phpcodeignitercodeigniter-2codeigniter-routing

提问by Satish Ravipati

Can someone tell me, where the issue is ??

谁能告诉我,问题出在哪里??

This is my controller

这是我的控制器

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');
        }
    }
}

Here is my routes.php

这是我的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-worldgives me 404 Page Not Founderror

localhost/ciproj/support/hello-world给我404 Page Not Found错误

If I use exit;after $this->load->view('templates/footer');, the page is showing me blank page.

如果我使用exit;after $this->load->view('templates/footer');,页面会显示空白页面。

I don't have anything in routes related to support and every other method is working Is there anything that i'm missing in routes ??

我在与支持相关的路线中没有任何内容,并且所有其他方法都在起作用我在路线中遗漏了什么吗?

Thanks for the help.

谢谢您的帮助。

回答by Hashem Qolami

Judging the title, first of all check if your server is running PHP using CGI/FastCGIor not (you could simply check that by phpinfo()).

判断标题,首先检查您的服务器是否正在运行 PHP CGI/FastCGI(您可以简单地通过 来检查phpinfo())。

If so, change the following in config.php:

如果是这样,请更改以下内容config.php

$config['uri_protocol'] = "REQUEST_URI";


Back to the topic, you could achieve that by using the single-line route below within your routes.phpfile:

回到主题,您可以通过在routes.php文件中使用下面的单行路由来实现这一点:

$route['support/(?!index)(?!delete)(:any)'] = "support/viewticket/";

And remove these lines from your __constructmethod:

并从您的__construct方法中删除这些行:

$urlarray = array("index","delete");
if(!in_array($this->uri->segment(2),$urlarray)){
    $this->viewticket($this->uri->segment(2));
}

Let me know how it works.

让我知道它是如何工作的。