Symfony implements the method for obtaining the request parameter in the behavior and template, symfonyrequest
This example describes how to obtain the request parameter in the Symfony implementation behavior and template. 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'):?> <P> Hello, <? Php echo $ sf_params-> get ('name')?>! </P> <? Php else:?> <P> Hello, JohnDoe! </P> <? 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.
Articles you may be interested in:
- A detailed explanation of the controller usage of Symfony2 learning notes
- Symfony2 development-controller usage instance analysis
- Symfony core class overview
- How to create a project using the symfony command
- Quick variable usage example of the Symfony Template
- Details about how to create a project and a template setting instance in the Symfony2 framework
- Symfony2 Study Notes plugin format Analysis
- System Route details for Symfony2 Study Notes
- Template usage of Symfony2 learning notes
- Symfony installation and configuration methods
- In-depth description of Symfony control layer