《PHP實戰:Symfony實現行為和模板中取得request參數的方法》要點:
本文介紹了PHP實戰:Symfony實現行為和模板中取得request參數的方法,希望對您有用。如果有疑問,可以聯系我們。
PHP實戰本文實例講述了Symfony實現行為和模板中取得request參數的辦法.分享給大家供大家參考,具體如下:
PHP實戰一.模板中取得參數
PHP實戰
<?php echo $sf_request->getParameter('name','namespace');?>
<?php echo $sf_request->getParameter('name');?>
PHP實戰二.行為中取得參數
PHP實戰
$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
PHP實戰希望本文所述對大家基于Symfony框架的PHP程序設計有所贊助.
《PHP實戰:Symfony實現行為和模板中取得request參數的方法》是否對您有啟發,歡迎查看更多與《PHP實戰:Symfony實現行為和模板中取得request參數的方法》相關教程,學精學透。維易PHP學院為您提供精彩教程。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/7329.html