【发布时间】:2012-06-23 04:19:54
【问题描述】:
我正在数据库中查询与在 url 段 www.site.com/post/24 中传递的 id 匹配的单个记录。
假设帖子24 不存在。处理未找到的数据库请求的安全且seo 兼容的方法是什么?
以下是我目前使用 Codeigniter 模型的解决方案:
function read_post($post_id) //argument is the value of the url segment
{
$user_id = $this->tank_auth->get_user_id();
$this->db->where('user_id', $user_id);
$this->db->where('post_id', $post_id);
$this->db->limit(1);
$query = $this->db->get('posts');
//check if record exists
if ($query->num_rows() > 0) //row is returned
{
return $query->row(); //passed to controller and view
}
else
{
show_404(); //generate 404 message
return FALSE; //------------------------or exit()?
}
}
请分享您自己的最佳方法/意见。
【问题讨论】:
标签: php mysql codeigniter http-status-code-404