Abhishek Sharma
Abhishek Sharma

Reputation: 3280

How can I generate dynamic urls in codeigniter?

In my application I am currently using the standard parameter passing, for example http://localhost/api/shops/deals/$shop_id

But i need the urls to be like http://localhost/api/shops/$shop_id/deals

How can I achieve that?

Upvotes: 1

Views: 635

Answers (1)

Rejoanul Alam
Rejoanul Alam

Reputation: 5398

Use application/config/routes.php file to do that. Like

$route['api/shops/(:num)/deals'] = 'api/shops/deals/$1';

Now when your URL will be http://localhost/api/shops/3/deals then it will execute as http://localhost/api/shops/deals/3

for more details https://codeigniter.com/user_guide/general/routing.html

Upvotes: 4

Related Questions