解读zf getPost
别看这个小小的函数,却提供了很多可变的功能
/**
* Retrieve a member of the $_POST superglobal
*
* If no $key is passed, returns the entire $_POST array.
*
* @todo How to retrieve from nested arrays
* @param string $key
* @param mixed $default Default value to use if key not found
* @return mixed Returns null if key does not exist
*/
public function getPost($key = null, $default = null)
{
if (null === $key) {
return $_POST;
}
return (isset($_POST[$key])) ? $_POST[$key] : $default;
}
1.获取全局的$_POST
2.返回相应key的POST
3.设置相应key的默认POST
4.注意isset函数,说明了其代码的严谨性