0

I have the following class in my controller (codeigniter)

class Books extends CI_Controller {

    function index($id = NULL){

       //model
       //view
    }

}

I have this link in my view file

<a href="<? echo base_url();">/books/index/<? echo $id ;?>  > Book1</a>

when I click on the above link the URL in the address bar looks like >

    http://localhost/my_web/books/index/1

But I am trying to make the URL look like-

     http://localhost/my_web/books/1

So, after studying this tutorial, in my application/config/routes.php I used the following code.

$route['books/:num'] = "books/index";

And then I changed my link to following code, but when I click on it, the page says 404 Page not found

   <a href="<? echo base_url();">/books/<? echo $id ;?>  > Book1</a>

Could you please tell how to achieve this?

Thanks in Advance :)

black_belt
  • 6,601
  • 36
  • 121
  • 185

2 Answers2

3

you are missing parameter in routes, Try:

$route['books/(:num)'] = "books/index/$1";
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
  • Correction... `$route['books/(:num)'] = 'books/index/$1';` you have to surround the `:num` in parenthesis otherwise it will match but not relate to `$1` ;) – Gavin Aug 14 '12 at 13:22
0

Set in the Route which is application/config/route.php

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

it definitely work for you route.

Ajeet Kumar
  • 805
  • 1
  • 7
  • 26