Symfony實現(xiàn)行為和模板中取得request參數(shù)的方法
更新時間:2016年03月17日 12:01:30 作者:智足者富
這篇文章主要介紹了Symfony實現(xiàn)行為和模板中取得request參數(shù)的方法,實例分析了Symfony針對行為和方法中參數(shù)獲取的技巧,需要的朋友可以參考下
本文實例講述了Symfony實現(xiàn)行為和模板中取得request參數(shù)的方法。分享給大家供大家參考,具體如下:
一.模板中取得參數(shù)
<?php echo $sf_request->getParameter('name','namespace');?> <?php echo $sf_request->getParameter('name');?>
二.行為中取得參數(shù)
$request->getParameter('name'); //模板中取得參數(shù) <?php echo $sf_params->get('name')?> //帶默認值的參數(shù) <?php echo $sf_params->get('name','default')?> //在模板中判斷一個參數(shù)是否存在 <?php if($sf_params->has('name')): ?> <p>Hello,<?php echo $sf_params->get('name')?>!</p> <?php else: ?> <p>Hello,JohnDoe!</p> <?php endif; ?> //包含所有參數(shù)的數(shù)組 $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程序設(shè)計有所幫助。
相關(guān)文章
PHP中exec函數(shù)和shell_exec函數(shù)的區(qū)別
這篇文章主要介紹了PHP中exec函數(shù)和shell_exec函數(shù)的區(qū)別,這兩個函數(shù)是非常危險的函數(shù),一般情況都是被禁用的,當然特殊情況下也會使用,需要的朋友可以參考下2014-08-08PHP 面向?qū)ο蟪绦蛟O(shè)計(oop)學習筆記 (二) - 靜態(tài)變量的屬性和方法及延遲綁定
靜態(tài)變量的類型關(guān)鍵字是static。本文主要是學習php中靜態(tài)屬性和靜態(tài)方法的使用方法和基本的示例以及延遲綁定2014-06-06Yii2中使用join、joinwith多表關(guān)聯(lián)查詢
這篇文章主要介紹了Yii2中多表關(guān)聯(lián)查詢(join、joinwith)的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-06-06