使用 url 助手
$this->load->helper('url');
$blog_slug = url_title('Mysite.com Goes live!');
echo $blog_slug //mysitecom-site-goes-live
// might differ slightly, but it'll do what you want.
生成对 url 友好的链接。
将此值存储在博客表 (url_title/url_slug) 中的字段中。
做一个功能:
class Journal extends controller
{
//make your index/constructor etc
function view($post)
{
$this->blog_model->get_post($post);
// etc - your model returns the correct post,
// then process that data and pass it to your view
}
}
您的 blog_model 有一个使用 CI 的 get_post 方法
$this->db->where('url_title', $post);
希望这是有道理的。
然后当您访问该页面时:
site.com/journal/view/mysite-goes-live
该函数将获取“mysite-goes-live”并将其传递给 view() 函数,该函数依次在数据库中查找相应的博客条目。