0

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

5
  • with .htaccess, it may be possible. Commented Jun 30, 2017 at 15:11
  • i think not possible how pass value in controller Commented Jun 30, 2017 at 15:15
  • instead of parameter, you can try slug.. Commented 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 left Commented Jun 30, 2017 at 15:20
  • why do you want to hide it? Commented Jun 30, 2017 at 15:21

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

if you want to pass parametre in hidden you need to add an input hidden that has an id value (in your situation here 2) and then you can submit ur form

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.