0

This is my URL :https://rentals.in/product/categories/41

Here 41 is the product id and its product name exist in DB is Electronics so i want to convert this URL as "https://rentals.in/product/categories/Electronics" dynamically using Routing function available in Codeigniter3.0. Is any callback function can use in routing for achieving above? or Any Other way?

Sherin Green
  • 308
  • 1
  • 3
  • 18
  • Possible duplicate of [Using slugs in codeigniter](https://stackoverflow.com/questions/3305786/using-slugs-in-codeigniter) – Habib Rehman Aug 28 '18 at 11:58

1 Answers1

0

CodeIgniter follow below routing by default to fetch data by their id, if you completely replace the id part and search by name then there would be chances of getting wrong data, it would give first matching name.

example.com/class/function/id/

I suggest you to create Url like this, and make last name part optional

rentals.in/product/categories/41/Electronics

Which will use id to get data and also display name of category

Just like SO does. Below both url opens same page.

//stackoverflow.com/questions/52051604

//stackoverflow.com/questions/52051604/how-to-replace-product-id-with-product-name-in-url-using-routing-in-codeigniter

Refer this answer to make optional param in CodeIgniter routing

Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109
  • We use URL like this "rentals.in/product/categories/41/Electronics" and set route as $route['signup'] = "user/signup"; $route['signup/(:num)'] = "user/signup/$1"; but nothing happens – Sherin Green Aug 28 '18 at 07:19