Welcome Guest, Not a member yet? Register   Sign In
Is there a managed way to use $_POST and $_GET
#1

[eluser]WebMada[/eluser]
Hello!

I used datas from a form. So I used the $_POST array to get them ($_GET does not exist for CI?)
I wonder if there is a managed way to used it instead of calling directly this array?
#2

[eluser]Maglok[/eluser]
There is.

First $_GET is gotten from the query string, which is disabled by default because CI uses your uri bits. You can set it up again, but it is not really neccesary. It is in the user_guide somewhere.

For POST, there is a more secure way in CI to grab it:
Code:
$this->input->post('name')
Where name is the variable you are grabbing.

It is in the input class (http://ellislab.com/codeigniter/user-gui...input.html) which is loaded by default.
#3

[eluser]WebMada[/eluser]
Thanks

So input->get() doesn't exist?
#4

[eluser]LifeSteala[/eluser]
Source: http://ellislab.com/codeigniter/user-gui...s/uri.html

For $_GET you need to use:

Code:
$this->uri->segment([segment], [default_value]);

Take for example:

http://www.domain.com/controller/method/value1/value2/

To get value2 you do the following..

Code:
$this->uri->segment(4, false);

Note: the false is used if there is no value in segment 4 - example:

http://www.domain.com/controller/method/value1/

Hope that helps!
#5

[eluser]WebMada[/eluser]
Thanks about GET

Curiosity: what about $_SESSION, i don't understand the user guide (http://ellislab.com/codeigniter/user-gui...sions.html)

For ex, what is the CI equivalent of $_SESSION['name'] ???
#6

[eluser]Maglok[/eluser]
$this->session->userdata('name');
#7

[eluser]LifeSteala[/eluser]
Follow the comments in this code:

Code:
// Set session in native PHP
$_SESSION['myName'] = "Joe Bloggs";

// Set session in CI
$this->session->set_userdata('myName', 'Joe Blogg');

// Retrieve and display session in native PHP
echo $_SESSION['myName'];

// Retrieve and display session in CI
echo $this->session->userdata('myName');

// Unset session in native PHP
$_SESSION['myName'] = "";
unset($_SESSION['myName']);

// Unset session in CI
$this->session->unset_userdata('myName');

How's that? Does that make sense?
#8

[eluser]WebMada[/eluser]
Great thanks !!!




Theme © iAndrew 2016 - Forum software by © MyBB