Welcome Guest, Not a member yet? Register   Sign In
proper mvc way of posting data to a form.
#1

[eluser]chubbypama[/eluser]
hi there. i have a web app i'm trying to rewrite the mvc way using code igniter.
i have a page called "saveData.php" which is called with 3 values passed in the querystring.

eg) saveData.php?val1=abc&val2=1&val3=dfd

I'm trying to create a new controller called "remoteClients" and it has a method called saveStatus.
but i'm not sure how to accept the 3 pieces of data.
i did notice in the code igniter documentation that you can still use querystring to pass data... but i'm wondering what other ways i can accomplish this / what is the recommended way.

thank you.
#2

[eluser]weboap[/eluser]
it may be just me but i think its a bad idea going thru activation the query string .... starting from the config.
but that said, you should take a look at :

http://ellislab.com/codeigniter/user-gui...s/uri.html

your url will be something like

http://www.yourdomain.com/remoteclients/.../abc/a/dfd

mean

http://www.yourdomain.com/remoteclients/.../val2/val3

you will be able to access the vals using

Code:
$val = $this->uri->segment(n);
//don't forget to clean $val.

hope it help!
#3

[eluser]WanWizard[/eluser]
In general you never update data through the URI, doesn't matter if you're using GET variables or URI segments.

You post data through HTTP POST, and don't process it until after proper validation.
#4

[eluser]weboap[/eluser]
i was explaining the way Ci will deal with the url, but @WanWizard is right i second him.
#5

[eluser]chubbypama[/eluser]
[quote author="WanWizard" date="1337362157"]In general you never update data through the URI, doesn't matter if you're using GET variables or URI segments.

You post data through HTTP POST, and don't process it until after proper validation.[/quote]

thanks for the post/response. here's another question then. i have a script that is going to be running on a box and will need to send data to my page every couple of minutes.
in my old version, i just had the script use a url like:

http://myserver/mysite/?var1=123&var2=123 etc.

i guess i'll have to see if i can do a http post from the script....
as far as the web page is concerned then, i would just code it as if i had a form, and the form was posted... is this correct?
#6

[eluser]Patrick Spence[/eluser]
[quote author="chubbypama" date="1337628336"][quote author="WanWizard" date="1337362157"]In general you never update data through the URI, doesn't matter if you're using GET variables or URI segments.

You post data through HTTP POST, and don't process it until after proper validation.[/quote]

thanks for the post/response. here's another question then. i have a script that is going to be running on a box and will need to send data to my page every couple of minutes.
in my old version, i just had the script use a url like:

http://myserver/mysite/?var1=123&var2=123 etc.

i guess i'll have to see if i can do a http post from the script....
as far as the web page is concerned then, i would just code it as if i had a form, and the form was posted... is this correct?[/quote]

Yes, just like a form. Checking $this->input->post('varname', TRUE);

You can use Curl to POST to pages, so if it is a shell script you can deal with the change in method fairly easily.

Here is one example of why you should not change data on a GET, only POST

http://thedailywtf.com/Articles/The_Spider_of_Doom.aspx

If you want to get plucky and more advanced on how you handle events like your update, Phil Sturgeon made a couple nice libraries for CI,

https://github.com/philsturgeon/codeigniter-restserver
https://github.com/philsturgeon/codeigniter-restclient

For example, I have a mail server application running on a host that handles sending all the emails out for all my domains, and each domain sends the emails to the central server with a rest PUT command.




Theme © iAndrew 2016 - Forum software by © MyBB