本文实例讲述了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>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/2290">
<img src="https://img.php.cn/upload/ai_manual/001/246/273/175686939683618.png" alt="AiPPT模板广场">
</a>
<div class="aritcle_card_info">
<a href="/ai/2290">AiPPT模板广场</a>
<p>AiPPT模板广场-PPT模板-word文档模板-excel表格模板</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="AiPPT模板广场">
<span>147</span>
</div>
</div>
<a href="/ai/2290" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="AiPPT模板广场">
</a>
</div>
<?php else: ?>
<p>Hello,JohnDoe!</p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</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框架的PHP程序设计有所帮助。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号