Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to yii getPost for array _POST vars?

Tags:

php

http-post

yii

Assuming i have

$_POST["x"]["y"] = 5;

how can i

Yii::app()->request->getPost('x[y]');

how can i retrieve the post variable by index ? and is there any yii function that checks for sql injection ? does the getPost do that check ?

Thank you .

like image 775
Rami Dabain Avatar asked Sep 06 '12 13:09

Rami Dabain


3 Answers

I am not familiar with yii, but looking at the source code for the function https://github.com/yiisoft/yii/blob/1.1.12/framework/web/CHttpRequest.php

You would do

$x = Yii::app()->request->getPost('x');
$y = $x['y'];

The getPost function WILL NOT prevent sql injection. Please read http://www.yiiframework.com/wiki/275/how-to-write-secure-yii-applications/#hh11 for more information on securing your yii application

like image 80
Kris Avatar answered Sep 24 '22 14:09

Kris


Yii2

$x = Yii::$app->request->post('x');
like image 37
frops Avatar answered Sep 25 '22 14:09

frops


With model Test it's look like this

$test = new Test();
$test->attributes = Yii::app()->request->getPost('x');   
$y = $test->getAttribute('y');
like image 2
hackil Avatar answered Sep 26 '22 14:09

hackil