Symfony实现行为和模板中取得request参数的方法_php实例

WBOY
Release: 2016-06-07 17:08:37
Original
708 people have browsed it

本文实例讲述了Symfony实现行为和模板中取得request参数的方法。分享给大家供大家参考,具体如下:

一.模板中取得参数

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

Copy after login

二.行为中取得参数

$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

Copy after login

希望本文所述对大家基于Symfony框架的PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template