How does Symfony obtain request parameters in templates and behaviors? This article mainly introduces the method of obtaining request parameters in Symfony's behavior and templates, and analyzes Symfony's techniques for obtaining parameters in behaviors and methods with examples. Friends in need can refer to it. I hope it will be helpful to everyone.
1. Obtaining parameters from the template
getParameter('name','namespace');?> getParameter('name');?>
2. Obtaining parameters from the behavior
$request->getParameter('name'); //模板中取得参数 get('name')?> //带默认值的参数 get('name','default')?> //在模板中判断一个参数是否存在 has('name')): ?>Hello,get('name')?>!
Hello,JohnDoe!
//包含所有参数的数组 $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
Related recommendations:
Detailed explanation of how symfony uses commands to create projects
Brief description of Symfony core classes
php symfony/var-dumper How to install the printing plug-in
The above is the detailed content of Detailed explanation of how Symfony obtains request parameters in templates and behaviors. For more information, please follow other related articles on the PHP Chinese website!