Welcome Guest, Not a member yet? Register   Sign In
Passing data to Controllers outside the URL
#1

[eluser]mokaloka[/eluser]
Hi,

i hope anyone can help me with this. My page have a HREF that looks like this:

/district/vdp-des-cotes-de-gascogne.

That link is created with url_helper (a modified version) from the string: "VdP des Côtes de Gascogne". We want to maintain that URL structure.

However, i cant just pass this is useless as parameter in the URL, since the database entries contain the string: "VdP des Côtes de Gascogne". So my question is: is there a way to pass data to controllers outside the URL. I have been experimenting with session data but it just not seem right. I have been thinking about som kind of POST-functionality with hidden fields, but I just assume that there is a smarter solution to this.

I can't be the only one having problems passing data to controllers containing uncommon character.

Grateful for any help.

Happy Halloween.
#2

[eluser]jedd[/eluser]
Hi mokaloka and welcome to the CI forums.

The way I avoid this type of problem is to use the id of the row that contains, in this case, "VdP des Côtes de Gascogne" - so my URL would be, say, /district/27

You say you want to maintain the URL structure, but I'm not sure if you mean the controller/method arrangement, or if you want to continue to not be able to use text strings sensibly in the URL.

Alternatively you could do a combination of - modifying config.php's entry for $config['permitted_uri_chars'] to be way more permissive in what you can put on the URL, and hope you catch all the extended characters that you might use - and then do a urlencode/urldecode thing on the way in and out of the URL generation. This is what I've done recently, but happily all I needed to add was the '+' character to my config, as I'm using the Strine dialect of English.

Really, though, I think the problem is the desire to have presentation data embedded in its natural form in a URL, and URL's just aren't the best place for presentation data.
#3

[eluser]mokaloka[/eluser]
Hi Jedd and thanks for welcoming me to the CI forum and for the quick reply!

Using the ID would not work here, since the database it's not normalized enough (however, our database has retrieved its data from a database which is normalized, but thats antoher story). We could however make a table with contaning the districts like this:

Field encoded: vdp-des-cotes-de-gascogne
Field name: VdP des Côtes de Gascogne

and use the Name field in the sql query used to obtain all districts.

But in the mean time, the urlencode/urldecode combined with setting the permitted characters in config.php is the way to go.

Your thoughts on the presentation data embedded in its natural form in the URL is also interesting. I am quite new to webprogramming (or it was like 10 years i worked with it, remember ASP?). I work in the mobile industry nowadays and its very different. But CI is actually great and having a forum like this is also very helpful.

See you around.
#4

[eluser]jedd[/eluser]
I reckon that if you are going to do this:

Quote:Field encoded: vdp-des-cotes-de-gascogne
Field name: VdP des Côtes de Gascogne

Why don't you do this (which is functionally the same)
Quote:Field encoded: 27
Field name: VdP des Côtes de Gascogne

The problem I see with converting VdP des Côtes de Gascogne to vdp-des-cotes-de-gascogne, is that VdP des Cotes de Gascôgne* would also get converted to the same thing - and so you effectively have a one-way hash function, rather than a two-way lookup. In other words, you'll have trouble guaranteeing that vdp-des-cotes-de-gascogne is unique OR you'll have to handle collisions when two of your entites encode to the same string.



* Forgive my obvious lack of understanding of your language - this is doubtless an impossible combination, but hopefully you see the point that I'm trying to make here.
#5

[eluser]mokaloka[/eluser]
Hi again Jedd,

I am well aware that the solution I am proposing is a nasty one in terms of normalizing databases. However, there is no risk in this particular scenario that "vdp-des-cotes-de-gascogne" would match something else. However, this is not the solution we are going for anyway it seems, not at the moment anyway. You presented a solution earlier which is the one we are probably going to try.

But the original question was somehow lost on the way, with this database discussion and all. I am still interested in how to supply data without passing it in the URL (like POST with hidden fields) using code igniter.

The lack of understanding of my languague is fine, since I don't really speak the language used in the example myself. But I am swedish not french, and I won't be insulted from now on! Smile

Take care!
#6

[eluser]jedd[/eluser]
[quote author="mokaloka" date="1257379082"]
But the original question was somehow lost on the way, with this database discussion and all. I am still interested in how to supply data without passing it in the URL (like POST with hidden fields) using code igniter.
[/quote]

You said you looked at session data, but it did not seem right. What seemed wrong with it?

Obviously you need to have some method to get the data in the first place - presumably a form, consequently some POST data. Once you've got that, you can store that in session data (which is pretty seamless). OTOH, having it in the URL means that users can share the URL around - a semi-RESTful approach, if you will.
#7

[eluser]BrianDHall[/eluser]
Session, cookie, POST, GET - I think that is about it as far as client-to-server communication goes.
#8

[eluser]jedd[/eluser]
Oh, and you can do POST + hidden fields with CI too, of course - it's even easier than plain vanilla PHP, once you use the form helper.
#9

[eluser]mokaloka[/eluser]
Thanks a lot for your input! The problem is solved now, and some interesting questions were raised. There are, as I see it, many different ways to use the MVC pattern and what to do what where and when. As I come from a differant area of programming (mobile industry, C and Java) with entirely different end-products, it was interesting to see how my architectural thinking worked with a Code Igniter solution.

I did some misstakes early on, and then I got the hang of it. I must say, if i haven't already done it, CI made the transition really easy. Top class.

(This should really be in the "Introduce Yourself" forum... I'll sort it out later)




Theme © iAndrew 2016 - Forum software by © MyBB