doumei4964 2014-05-26 19:49
浏览 67

CI路由器没有结果404错误

I'm working on a project to get a vanity_url to resolve a record from the database.

e.g. abc.com/ThisRecord -> shows the record from database where vanity_url=ThisRecord

In the route file I have used this:

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

How would I get an error 404 if no such record exists?

  • 写回答

1条回答 默认 最新

  • douren7921 2014-05-26 20:35
    关注

    CodeIgniter has a show_404() function which will send an HTTP 404 header and return the template found in: application/errors/error_404.php. See the user guide for more information.

    When calling the list_page() function, you just need to check if the record exists. If the record does exist, load the relevant view, otherwise, call the show_404() function.

    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();
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序