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 :)

1
  • I think: $route['books/:num'] = "books/index/$1"; – as it says in the tutorial you linked to ;) Commented Aug 10, 2012 at 12:07

2 Answers 2

3

you are missing parameter in routes, Try:

$route['books/(:num)'] = "books/index/$1";
Sign up to request clarification or add additional context in comments.

1 Comment

Correction... $route['books/(:num)'] = 'books/index/$1'; you have to surround the :num in parenthesis otherwise it will match but not relate to $1 ;)
0

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

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

it definitely work for you route.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.