0
Friends, I am developing a blog in CI. And thinking about the blog SEO, I would like the URL instead of being presented this way:
I would like it to be shown with the title of the post.
My Route is like this:
$route['blog/(:num)'] = "blog/postagem/$1";
My controller is like this (don’t worry about the gambiarra, as soon as I solve this SEO issue I create the Models correctly):
class Blog extends CI_Controller {
public function postagem($id){
$this->db->where('id', $id);
$data['blog'] = $this->db->get('blog')->result();
$this->load->view('site/blog/postagem', $data);
}
public function home(){
$data['blog'] = $this->db->get('blog')-> result();
$this->load->view('site/blog/home' , $data);
}
View posting:
<?php foreach ($blog as $post ) { ?>
<h1><?php echo $post->titulo; ?>- <small><?php echo $post->categoria;?></small></h1>
<p><?php echo $post->texto;?></p>
<hr>
<?php } ?>
View Home:
<?php foreach ($blog as $post ) { ?>
<a href="<?php echo site_url('blog/postagem');?>/<?php echo $post->titulo; ?>"><?php echo $post->titulo?></a>
<hr>
<?php } ?>
I would like to know how the CI will actually identify that the title in the url corresponds to an ID on Route.. I can not understand, someone can help me?
Show ! This will help me.. I didn’t think there would be anything like that there! during this time I found in an American forum the following solution: <a href="<? php echo site_url(). 'blog/post/'. $post->id. '/'. implode('-',explode(' ',preg_replace('/[ w]+/','', $post->title))) ? > "><? php echo $post->title? ></a>
– Rafael Rotiroti