Symfony如何实现行为和模板中取得request参数

这篇文章将为大家详细讲解有关Symfony如何实现行为和模板中取得request参数,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

具体如下:

一.模板中取得参数

<?php echo $sf_request->getParameter('name','namespace');?>
<?php echo $sf_request->getParameter('name');?>

二.行为中取得参数

$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

关于“Symfony如何实现行为和模板中取得request参数”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。