How to have url's like domain.com/<article-name> in CodeIgniter -


i have articles controller , view function in show individual article, url's like

http://domain.com/articles/view/<article-id>/<article-title>

my code:

class articles extends ci_controller {      function view($id=null,$slug=""){         //code fetch article details db id     } } 

how make url's http://domain.com/<article-title>

thank you.

define controllers in routes config addressing own methods. @ end of routes config add following rule --

$route['(:any)']   = 'articles/view/$1'; 

all requests other defined route served artcile/view controller method.

next part create mapping table map article titles article ids. can article title

$this->uri->segment(1); 

in view function.

whenever article updated title, update mapping table well.


Comments