请看下面的链接结构
http://stackoverflow.com/questions/10672712/voting-system-like-stackoverflow
在上面的链接中10672712
我猜是问题 ID,因为如果您检查以下链接,您将到达与上面相同的位置:
http://stackoverflow.com/questions/10672712
现在,如果您使用上面的链接,您会注意到在浏览器的地址栏中,该链接会自动在问题 id 之后添加问题标题(作为标题),并且它看起来就像上面的第一个链接一样。
我正在尝试使用 Codeigniter 创建一个基于文章的网站。为了显示特定的文章,我有一个控制器,如下所示:
function articles(){
$id=$this->uri->segment(3);
$this->load->model('mod_articles');
$data['records']=$this->mod_articles->list_articles($id);
$this->load->view('view_article',$data);
}
我的型号:
function list_articles($id)
$this->db->select('*');
$this->db->from('cx_article');
$this->db->join('cx_author', 'cx_author.author_id = cx_article.author_id');
$this->db->where('article_id', $id);
$query = $this->db->get();
if ($query->num_rows() > 0)
{ return $query->row_array();
}
else {return NULL;}
}
如果你点击这个->localhost/my_base_url/my_controller/my_funtion/article_id
然后我的文章就出现了。现在我想要实现的是如果有人打localhost/my_base_url/my_controller/my_funtion/article_id
我想在article_id之后自动添加文章标题作为slug。(就像我上面给出的例子一样)
你能告诉我该怎么做吗?
Thanks:)
P.S 在我的数据库表中,有一列名为article_slug
,其中我将文章标题存储为 slug(例如:voting-system-like-stackoverflow)。