Good, I'm starting to use php and codeigniter as framework, and I want to know if it is possible to modify the url, for example I have the following user controller and inside an edit method to edit the data of a user the url would look like this: http://localhost/sis/user/edit/2, I want to know if it is possible to hide the parameter that passed to the method of my controller
-
with .htaccess, it may be possible.ArtisticPhoenix– ArtisticPhoenix2017-06-30 15:11:58 +00:00Commented Jun 30, 2017 at 15:11
-
i think not possible how pass value in controllerHothi Jimit– Hothi Jimit2017-06-30 15:15:45 +00:00Commented Jun 30, 2017 at 15:15
-
instead of parameter, you can try slug..kishor10d– kishor10d2017-06-30 15:16:45 +00:00Commented Jun 30, 2017 at 15:16
-
Then it is possible to change it, by the name instead of showing the id?, that another option is leftFeRcHo– FeRcHo2017-06-30 15:20:40 +00:00Commented Jun 30, 2017 at 15:20
-
why do you want to hide it?vaso123– vaso1232017-06-30 15:21:39 +00:00Commented Jun 30, 2017 at 15:21
2 Answers
No, it is not possible to hide the parameters that are passed to your controller if you're using them in your URL.
There are quite some fancy things that you can do with Codeigniter routing (https://www.codeigniter.com/userguide3/general/routing.html), but hiding parameters isn't one of them. If you want to 'hide' the parameter(s), you will have to use another way of passing these parameters. This can be, for instance, passing the parameters through a hidden field in your user edit form, like so:
<form action="http://localhost/sis/user/edit">
<!-- Hidden input field that contains user id -->
<input type="hidden" name="userid" value="2">
<input type="text" name="firstname">
<input type="text" name="lastname">
<input type="submit" value="Edit user">
</form>
You can fetch your user ID in your controller like so: $_POST['userid']. Or the CodeIgniter way of using $_POST, $this->input->post('userid')