Zabs
Zabs

Reputation: 14142

Yii - simplify retrieving the $_POST var data using getPost()

I have the following Yii code and would like to minimise it if possible:

$request = Yii::app()->request->getPost('request');
$username = $request['model']['username'];

Is it possible to minimise this to have this work something like this so its all on a single line for instance? (note the code below doesn't work)

$username = Yii::app()->request->getPost('request['model']['username']'); 

Upvotes: 1

Views: 114

Answers (1)

Developerium
Developerium

Reputation: 7265

as you can see below (in class CHttpRequest):

public function getPost($name,$defaultValue=null)
{
    return isset($_POST[$name]) ? $_POST[$name] : $defaultValue;
}

if you can put it in $name, it will get returned :D

Upvotes: 1

Related Questions