Welcome Guest, Not a member yet? Register   Sign In
SEO friendly urls http://example.com/mymethod,name_of_article,2
#1

[eluser]jacobson[/eluser]
Hello I wanted to create more friendly urls for my CI application with a structure : http://example.com/mymethod,name_of_article,2. How can I make my app to examine URL like this and take it's 1'st parameter as method in the controller, second as the name of article (for SEO) and last - article ID.

Thx for help
#2

[eluser]ravengerpl[/eluser]
For example your method is named "post" and controller "blog". To get urls like
Code:
mysite.com/posts,name,id
:

routes.php
Code:
$route['posts,(:any),(:num)'] = "blog/post/$1/$2"

blog.php
Code:
public function post($name, $id)
{
$data['post'] = $this->post_model->get_post($name, $id);
}

post_model.php
Code:
public function get_post($name, $id)
{
$query = $this->db->get_where('post_table', array('post_name' => $name, 'post_id' => $id));
return $query->row_array();
}

There may be typos somewhere but hope you get the idea. Remember to add some error handling (when you deleted post from database and someone clicked on old link etc.).
#3

[eluser]jacobson[/eluser]
Yup i think ill make it that way. The title of the post won't be used in queries, just the id Smile but anyway thanks for help.




Theme © iAndrew 2016 - Forum software by © MyBB