【发布时间】:2011-06-25 20:55:32
【问题描述】:
我有一个奇怪的问题,请耐心等待。我正在使用 _remap 函数在我的 URI 中实现 example.com/user/username 协议,并且我正在使用以下代码:
function _remap()
{
//URI Segment I am retrieving (this part works for me)
$profile_name = $this->uri->segment(2,0);
// Query the DB where user_name (column in DB) == $profile_name
$query = $this->db->get_where('users', array('user_name' => $profile_name));
// Load user data when URI segment is retrieved, load page
foreach($query->result() as $row){
$this->load->view('user_view', $data);
}
}
所以我的问题是,每当我输入一个无效的 URI 段时,即在数据库中找不到它,它只会返回一个空白页。我尝试了一堆条件语句,但基本上我想要这个算法:
if $profile_name = FOUND (in DB)
display page
else
redirect to error page
就像我说的,我可以让它接受有效的数据库用户名,但如果是无效的,它只会显示一个空白页。我认为这是因为我在 segment(2,0) 函数中包含了 0 参数。让我知道您的想法...非常感谢!
附:以防万一您想知道为什么我不使用路由功能,我不确定是否可以通过路由来完成所有这些工作(无论如何都要对照数据库进行检查)。
【问题讨论】:
标签: php mysql codeigniter uri codeigniter-url