Symfony2controller, symfony2. Symfony2controller, symfony21, basic concepts: an http Request input (Request): header information, get information, post data, and other outputs (Response): symfony processed returned messages symfony2 controller, symfony2
1. Basic concepts
One http Request (Request): header information, get information, post data, etc.
Response: The information returned by symfony after processing, including the page, json string, and URL jump.
2. Request
$ This-> getRequest ()
Httpie tool
HTTPie (read aych-tee-pie) is an HTTP command line client. The goal is to make the interaction between CLI and web services as user-friendly as possible.
Install reference http://blog.csdn.net/pzw_0612/article/details/46521965
Http://www.cnblogs.com/huangjacky/archive/2012/03/28/2421866.html
Simulate form submission (post) with httpie)
>http -f post http://localhost:8000/app_dev.php/page/test name=lily
3. Response
Use Symfony \ Component \ HttpFoundation \ Response; // do not reference the errorUse Symfony \ Component \ HttpFoundation \ JsonResponse; use Symfony \ Component \ HttpFoundation \ RedirectResponse; class DefaultController extends Controller {/*** @ Route ("/page/test1 ") */public function test1Action (){
// If no template is used, directly output the content or jump to // return new RedirectResponse ('http: // www.cnblogs.com/tianxintian22 /'); redirect // return new JsonResponse (array ('a' => 'abcdef '); return json string return new Response ('20140901 ');}}
4. session
$this->getRequest()->getSession()->set('b', 'ni hao!');$this->getRequest()->getSession()->get('b');
If the session value cannot be correctly obtained, it may be that the session permission in the app/cache/dev directory is incorrect.
// Call flashmessage, which can only be displayed once and is discarded. it is generally used in form User information prompts. // php
$ This-> getRequest ()-> getSession ()-> getFlashBag ()-> add ('notic', 'You have something wrong ');
// Twig
{% For flashMessage in app. session. flashbag. get ('notice ') %}
{FlashMessage }}
{% Endfor %}
Http://www.bkjia.com/PHPjc/1100395.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1100395.htmlTechArticlesymfony2 controller, symfony2 1. basic concepts an http Request input (Request): header information, get information, post data and other outputs (Response): symfony processed returned messages...