-1

routes.php:

$route['services'] = 'woods/services';

output:

http://localhost:8079/works/Woods/services?id=1

I would like to hide this id (?id=1).

Alex
  • 9,215
  • 8
  • 39
  • 82
  • would this work: http://localhost:8079/works/Woods/services/1? or you don't want to see 1 at all? also is the id necessary? – Alex Feb 01 '18 at 07:49

1 Answers1

0

If you want to not show ?id you can do the following in your controller (url: Woods/services/1):

public function index($id = null) {

    if (is_null($id)) {
        show_404();
    }

    // you can now use your $id variable however you want, this is
    // the same as a get

}

Otherwise you have to use sessions or set a cookie but this would require you to either set the session variable of the id before the user clicks the href for that specific id (which unless your a mind reader isn't viable); which means you would need that href to trigger ajax to fire a controller function that sets the session variable with that id and then in js redirect to the page /Woods/services where you retrieve the session variable with the id (not pretty). Or again, you will have to route to an inbetween function that will do the session variable settings of the id and then redirect and hopefully the user won't see the id in between redirects.

Basically, its not hard, just cumbersome, and there is no real issue with having a url that looks like: localhost:8079/works/Woods/services/1. The only time that 1 could be a potential issue is if you are trying to do some crazy stuff that directly inserts into a database.

Alex
  • 9,215
  • 8
  • 39
  • 82