I'm currently studing symfony framework.
and I could not found the answer of how differe开发者_开发技巧nt between $_GET
and $request->getParameter()
.
I can understand the $request->getPrameter() can be used for,
if(isset($_GET['test'])){
$test = $_GET['test'];
}else{
$test = 'Unknown';
}
to
$request->getParameter('test','Unknown');
and anything else? I was expect it filter XSS but I think it doesn't.
For me, $_GET
way is much easier, but I feel like I should use the $request->getParameter()
So, I'd like to know exactly how diffrence.
Thanks! :)
Use:
$request['parameter']
This is equivalent to $request->getParameter('parameter', null)
.
Note that $request->getParameter
differs from $_GET
in that it returns all parameter types. $request->getGetParameter
is equivalent to $_GET
.
If you access a request parameter like:
$request->getParameter('parameter');
it can be the value of $_GET['parameter'] or $_POST['parameter'] as well. It is useful as normally you don't care whether the value is coming through post or get method.
You should infact be using $request->getGetParameter('parameter')
if you're specifically after a get parameters.
$request->getGetParameter('parameter')
is the equivalent of $_REQUEST['parameter']
which may not result in the desired behaviour.
Also worth noting that the sfWebRequest object is available in your views via $sf_request
i.e. $sf_request->getGetParameter('parameter')
精彩评论