Home  >  Article  >  Backend Development  >  How to obtain request parameters in Symfony implementation behavior and templates, symfonyrequest_PHP tutorial

How to obtain request parameters in Symfony implementation behavior and templates, symfonyrequest_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:56:53872browse

The method of obtaining request parameters in Symfony implementation behavior and templates, symfonyrequest

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

<&#63;php echo $sf_request->getParameter('name','namespace');&#63;>
<&#63;php echo $sf_request->getParameter('name');&#63;>

2. Obtain parameters in behavior

$request->getParameter('name');
//模板中取得参数
<&#63;php echo $sf_params->get('name')&#63;>
//带默认值的参数
<&#63;php echo $sf_params->get('name','default')&#63;>
//在模板中判断一个参数是否存在
<&#63;php if($sf_params->has('name')): &#63;>
<p>Hello,<&#63;php echo $sf_params->get('name')&#63;>!</p>
<&#63;php else: &#63;>
<p>Hello,JohnDoe!</p>
<&#63;php endif; &#63;>
//包含所有参数的数组
$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.

Articles you may be interested in:

  • Detailed explanation of controller usage in Symfony2 study notes
  • Example analysis of controller usage in Symfony2 development
  • Symfony core classes Overview
  • How to create a project using the symfony command
  • Shortcut variable usage examples of Symfony templates
  • Detailed explanation of project creation and template setting examples of Symfony2 framework
  • Learning Symfony2 Plug-in format analysis of notes
  • Detailed explanation of system routing of Symfony2 study notes
  • Detailed explanation of template usage of Symfony2 study notes
  • Installation and configuration method of Symfony
  • Symfony In-depth explanation of the control layer

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1111329.htmlTechArticleSymfony implementation behavior and the method of obtaining the request parameter in the template, symfonyrequest This article describes the Symfony implementation behavior and the method of obtaining the request parameter in the template request parameter method. Share it with everyone for everyone...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn