您可以使用網址區段進行帖子查找。 (這些my-first-post
就像通常稱爲slu strings的字符串)。您必須預先生成這些文件並將它們與帖子一起保存。
您可以使用路由配置的$route['404_override']
將每個不可路由的路徑指向控制器。一旦你的設置,你將不得不與相關博客文章的參數進行查詢,如果它的發現服務的帖子內容,如果沒有送出一個普通404事情是這樣的:
// application/config/routes.php
$route['404_override'] = 'blog/show_post'; // controller/action
// application/controllers/blog.php
class Blog extrends CI_Controller {
public function show_post() {
// get the first segment, the "first-post" from http://example.com/first-post
$slug = $this->uri->segment(0);
$post = $this->posts->find_by_slug($slug); // imaginary posts model with db query
if (!$post) { // if the post not found by slug
show_404(); // return 404 as usual
} else {
$this->load->view('blog/show', array($post)); // post found, display it
}
}
}
這是不可能的,由於控制器必須解決通過GET發送的數據,您必須在項目的ID或名稱(或每次2個) – csotelo