Welcome Guest, Not a member yet? Register   Sign In
Hide parameter from URL
#1

Hi,
I have a controller that requires the ID of a given table. The ID shows up on the URL but I need that to be hidden.
Is there a way to pass a parameter to the controller but hiding it from the URL?
Please note I'm not passing the variable through a form.

Thanks!
Reply
#2

you mean get the id of an entry in a database?

you can use models ,one for each table to "model data" eg in model

public function getArticle($slug)

{
return $this->asArray()
->where(['slug' => $slug])
->first();

}

from controller i pass in $slug, from what gets returned i can get values across all fields, including id
Reply
#3

(11-16-2020, 03:03 AM)captain-sensible Wrote: you mean get the id of an entry in a database?

you can use models ,one for each table to "model data" eg in model

public function getArticle($slug)

{
return $this->asArray()
    ->where(['slug' => $slug])
    ->first();

}

from controller i pass in $slug, from what gets returned i can get values across all fields, including id

No, what I mean to say is that I already have the ID and I'm passing it to a controller as a parameter. For example the URL will look like "localhost/controller/ID".

I don't want the ID to show on the URL so that users cannot mess around with URLs. Essentially I want to display only "localhost/controller" on the URL
Reply
#4

The way I do it is to use a hidden form input with the id which can be set from the controller etc.;

then use a get post in the controller.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(This post was last modified: 05-04-2023, 09:51 AM by Corsari.)

kindly
to extend the initial question
which is the technique to be used to keep the URL params not viewable in the URL?

e.g. I need to show and allow to browse a table which is altogether HMTL table in the view showing an entire table of the DB

In my case the URL params would be filters on top of the view table with checkboxes dropdowns radios etc etc
E.G. one column is users name one column is active/inactive (checkbox), one column is nation (drop down where to select the nationality) one column is male/female (radio)
so applying the filters currently, the URL/admin/users/list becomes URL/admin/users/list?page_group1=1&active=0&nation=france&gend=male

so back to the initial question.
Which is the technique to adopt in CodeIgniter to have the parameters "?page_group1=1&active=0&nation=france&gend=male" to be passed as if in the URL but not printed/shown in the URL?
- and possibly, if e.g I click one of the links of the pagination, to be kept set as they are
- and how to manage the change of one of the filters

thank you for any TIP
Reply
#6

use SESSION?
Reply
#7

That is the classic method
I'm asking if in Codeigniter is conceived for some technique that avoids showing the URL query strings
Reading the guide I see a set of utilities for the URL and params query
but the guide doesn't cover the technique for my question
Reply
#8

Is this what your tring to do?

stackoverflow -> How to hide query string from url using .htaccess?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#9

(This post was last modified: 05-04-2023, 11:46 PM by Corsari.)

Hello InsiteFX
Thank you for your intervention
I have seen some apps' codes built on CI an I guessed those query strings are managed internally as properties
Is it possible?
That is what I mean as "Codeigniter (or PHP MVC framework in general) technique"
Or I can turn the question this way, In your development, for the purpose above, do you make use of
- some Codeigniter utilities
- sessions
- htaccess as you linked
?

Or more simply your query string is visible and managed as in a classic PHP app (not MVC)

Thank you
Reply
#10

I actually use both methods, sessions and form hidden fields.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB