CI路由器没有结果404错误


CI Router no result 404 error

我正在做一个项目,得到一个vanity_url从数据库中解析一个记录。

。abc.com/ThisRecord ->显示数据库中vanity_url=ThisRecord

的记录

在路由文件中,我使用了这个:

$route['(:any)'] = 'listing_controller/list_page/$1'; // Resolved the Vanity_URL Query

如果没有这样的记录存在,我怎么得到错误404 ?

CodeIgniter有一个show_404()函数,它将发送一个HTTP 404头并返回在:application/errors/error_404.php中找到的模板。查看用户指南获取更多信息。

调用list_page()函数时,只需要检查记录是否存在。如果该记录存在,则加载相关视图,否则,调用show_404()函数。

function list_page($id)
{
    if (/* the record exists */)
    {
        // The record does exist - do what you want, load a view etc.
        $this->load->view('your_view');
    }
    else
    {
        // The record doesn't exist, show the 404 page
        show_404();
    }
}