search
Homephp教程php手册Symfony实现行为和模板中取得request参数的方法,symfonyrequest

Symfony实现行为和模板中取得request参数的方法,symfonyrequest

本文实例讲述了Symfony实现行为和模板中取得request参数的方法。分享给大家供大家参考,具体如下:

一.模板中取得参数

<&#63;php echo $sf_request->getParameter('name','namespace');&#63;>
<&#63;php echo $sf_request->getParameter('name');&#63;>

二.行为中取得参数

$request->getParameter('name');
//模板中取得参数
<&#63;php echo $sf_params->get('name')&#63;>
//带默认值的参数
<&#63;php echo $sf_params->get('name','default')&#63;>
//在模板中判断一个参数是否存在
<&#63;php if($sf_params->has('name')): &#63;>
<p>Hello,<&#63;php echo $sf_params->get('name')&#63;>!</p>
<&#63;php else: &#63;>
<p>Hello,JohnDoe!</p>
<&#63;php endif; &#63;>
//包含所有参数的数组
$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控制层深入详解
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

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

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

Dreamweaver Mac version

Visual web development tools

MantisBT

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

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment