How to hide data from URL string on Codeigniter

1.7k Views Asked by At

I am beginner on Codeigniter so I need help.

I am making blog site with Codeigniterand I don't know how to hide controller class, and ID from URL.

Like I have generated following URL: http://localhost/codeigniter/index.php/content/some-title/123.

  1. content is my controller class name.
  2. some-title is my article title.
  3. 123 is my article id.

I want to keep only title to show.

For example: http://localhost/codeigniter/index.php/some-title.

Any help would be appreciated!!!

3

There are 3 best solutions below

1
R.Surya On

You has add your link config/routes.php

http://localhost/codeigniter/index.php/content/some-title/123

Ex: $route ['some-title/(: any)']  = 'content/some-title/$123';
0
Jens T On

You can do this:

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

and in your content controller you must have a method like the one follow:

public funtion view($pagetitle){…}
0
Ankur Singh On

In the routes.php make sure you are using this line after your other routes which starts with some text.

$route['(:any)'] = 'content/show_article_post/$1';

Also make sure your slug for each article is unique in your database. There is no other way to send hidden id from get request.