Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of getPost over $_POST

Tags:

post

yii

Are there any advantages of Yii::app()->request->getPost() over $_POST?

I feel it makes the code too much object oriented.

like image 582
Mohammed H Avatar asked Feb 14 '23 18:02

Mohammed H


1 Answers

CHttpRequest::getPost() checks if the parameter exists first and if not it returns a default value that you can pass to it.

Here is its actual implementation:

public function getPost($name,$defaultValue=null)
{
    return isset($_POST[$name]) ? $_POST[$name] : $defaultValue;
}
like image 72
topher Avatar answered Feb 22 '23 15:02

topher