Symfony实现行为和模板中取得request参数的方法,symfonyrequest
本文实例讲述了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框架的PHP程序设计有所帮助。
您可能感兴趣的文章:
- Symfony2学习笔记之控制器用法详解
- Symfony2开发之控制器用法实例分析
- Symfony核心类概述
- 使用symfony命令创建项目的方法
- Symfony模板的快捷变量用法实例
- Symfony2框架创建项目与模板设置实例详解
- Symfony2学习笔记之插件格式分析
- Symfony2学习笔记之系统路由详解
- Symfony2学习笔记之模板用法详解
- Symfony的安装和配置方法
- Symfony控制层深入详解

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
