symfony2 controller,symfony21、基本概念
一次http请求 输入(request):header信息、get信息、post数据等
输出(response):symfony经过处理返回的信息,包括页面、json字符串、url跳转等
2、request
$this->getrequest()
httpie工具
httpie (读aych-tee-tee-pie)是一个 http 的命令行客户端。其目标是让 cli 和 web 服务之间的交互尽可能的人性化。
安装参考http://blog.csdn.net/pzw_0612/article/details/46521965
http://www.cnblogs.com/huangjacky/archive/2012/03/28/2421866.html
用httpie模拟表单提交(post)
>http -f post http://localhost:8000/app_dev.php/page/test name=lily
3、response
'abcdef'));返回json串 return new response('11111111111'); }}
4、session
$this->getrequest()->getsession()->set('b', 'ni hao!');$this->getrequest()->getsession()->get('b');
如果不能正确获取到session的值,可能是app/cache/dev目录下session的权限不对。
//调用flashmessage,只能显示一次就被抛弃,一般用在表单用户信息提示//php
$this->getrequest()->getsession()->getflashbag()->add('notice','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、基本概念 一次http请求 输入(request):header信息、get信息、post数据等 输出(response):symfony经过处理返回的信...