Method for obtaining request Parameters in Symfony implementation behavior and template _ php instance

Source: Internet
Author: User
This article describes how to obtain request Parameters in Symfony implementation behaviors and templates. The example shows how Symfony obtains parameters in behavior and method, for more information about how to obtain request Parameters in the Symfony implementation behavior and template, see the example in this article. We will share this with you for your reference. The details are as follows:

1. Obtain parameters in the template

<?php echo $sf_request->getParameter('name','namespace');?><?php echo $sf_request->getParameter('name');?>

2. Get parameters in the action

$ Request-> getParameter ('name'); // obtain parameters in the template <? Php echo $ sf_params-> get ('name')?> // Parameters with default values <? Php echo $ sf_params-> get ('name', 'default')?> // Determine whether a parameter exists in the template <? Php if ($ sf_params-> has ('name'):?>

Hello, <? Php echo $ sf_params-> get ('name')?>!

<? Php else:?>

Hello, JohnDoe!

<? Php endif;?> // Array containing all parameters $ request-> getParameterHolder ()-> getAll () // complete URI path // 'HTTP: // localhost/myapp_dev.php/mymodule/myaction 'geturi () // '/mymodule/myaction' getPathInfo () // $ hasFoo = $ this-> getRequest () in the action () -> hasParameter ('foo'); $ hasFoo = $ this-> hasRequestParameter ('foo'); // Shorter version $ foo = $ this-> getRequest () -> getParameter ('foo'); $ foo = $ this-> getRequestParameter ('foo'); // Shorterversion

I hope this article will help you design PHP programs based on the Symfony framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.