Home >Backend Development >PHP Tutorial >How to obtain request parameters in Symfony implementation behavior and templates, symfonyrequest_PHP tutorial
The example in this article describes the method of obtaining request parameters in Symfony implementation behavior and templates. Share it with everyone for your reference, the details are as follows:
1. Obtaining parameters from the template
<?php echo $sf_request->getParameter('name','namespace');?> <?php echo $sf_request->getParameter('name');?>
2. Obtain parameters in behavior
$request->getParameter('name'); //模板中取得参数 <?php echo $sf_params->get('name')?> //带默认值的参数 <?php echo $sf_params->get('name','default')?> //在模板中判断一个参数是否存在 <?php if($sf_params->has('name')): ?> <p>Hello,<?php echo $sf_params->get('name')?>!</p> <?php else: ?> <p>Hello,JohnDoe!</p> <?php endif; ?> //包含所有参数的数组 $request->getParameterHolder()->getAll() //完整的URI路径 //'http://localhost/myapp_dev.php/mymodule/myaction' getUri() //'/mymodule/myaction' getPathInfo() //在action中 $hasFoo =$this->getRequest()->hasParameter('foo'); $hasFoo = $this->hasRequestParameter('foo');//Shorter version $foo =$this->getRequest()->getParameter('foo'); $foo =$this->getRequestParameter('foo'); //Shorterversion
I hope this article will be helpful to everyone’s PHP program design based on the Symfony framework.