0
votes

What would be the best way to get uri segment via parameter in controller? i have used following code but not working

uri as

http://localhost/home/23

class Home extends CI_Controller
{


   public function index($para){
    echo $para;
   }
}

Above uri results in 404 page not found error.How to solve such problem and get the id as parameter in index function.

1
$this->uri->segment('4'); not sure about ('3') or ('4') - Deep Kakkar
My old apps worked in above code but now not working i just need reason for the problem - Shibin Raju Mathew
Is base_url defined correctly ? - Deep Kakkar

1 Answers

2
votes

You can write routing in your routes.php file.

File path : application/config/routes.php

$route['home/(:any)'] = 'home/index/$1';

OR

$route['home/index/(:any)'] = 'home/index/$1';

I hope it will help.