Welcome Guest, Not a member yet? Register   Sign In
uri segment returns unexpected result
#1

[eluser]fatman[/eluser]
Hi,

I have a table with value and an Edit button next to each value, when the user click the Edit button the url looks like this: http://localhost/admin/job/edit/job name

I use uri->segment to get the job name, but when it has a space it is replaced by '_'.

So if the job is called 'my job', i get 'my_job', how can i get the real value?

Thanks.
#2

[eluser]LuckyFella73[/eluser]
Assuming you have some db tables with all your informations stored in
you should better work with ids as reference instead of job titles.
You can use "join" in your queries to display the job title in your
edit-table but work with the id "internally".
#3

[eluser]fatman[/eluser]
Thank u for the quick reply.

I forgot to mention that i'm reading/writing the info to an XML not DB, and i need to search the XML by name.

So unfortunately, I can't use your advise Sad

is there a different way?
#4

[eluser]LuckyFella73[/eluser]
I didn't work with XML files in that way yet. Just a thought:

Can't you wrap every single job in your XML file with an id-tag
and find the matching job that way. Or do you need the job title
in your url for any reason?
#5

[eluser]fatman[/eluser]
Adding an id tag requires also managing the id (making sure it's unique, while letting the user add/update/delete), which is something i wanted to avoid, but if there is no other way, i'll guess i go that way.
#6

[eluser]Rok Biderman[/eluser]
How about running str_replace on it to remove the underscore?
#7

[eluser]LuckyFella73[/eluser]
If I got him right he passes the jobtitle to his method to
get the matching part inside his xml file. If you modify the
needed string in any way you won't find the matching part in
your xml file anymore.
#8

[eluser]Rok Biderman[/eluser]
Don't think that is the case really. Even if he was he still has time to do some processing before he uses the value in any way. When the underscore is added it does what you described and with str_replace you just return it into previous state. Provided you disallow for underscores in job titles in the first place. I think fatman will have to tell us if it could work.
#9

[eluser]LuckyFella73[/eluser]
You are right maybe it could work. I thought about that too in the
beginning. It's just when you have letters like ä ü ö etc. it
becomes tricky more and more to set up all the rules. That's why
I suggested to work with ids if possible. But if the job titles
are all "pure english" it would be a way to think about.
#10

[eluser]Rok Biderman[/eluser]
Ids would of course be preferable, as would the use of relational database. There is indeed a lot to consider when doing validation if you do it this way. Maybe managing ids in xml isn't that much of a work after all Smile




Theme © iAndrew 2016 - Forum software by © MyBB