一、基本概念php
一次http请求 输入(Request):header信息、get信息、post数据等html
输出(Response):symfony通过处理返回的信息,包括页面、json字符串、URL跳转等web
二、Requestjson
$this->getRequest()session
httpie工具架构
HTTPie (读aych-tee-tee-pie)是一个 HTTP 的命令行客户端。其目标是让 CLI 和 web 服务之间的交互尽量的人性化。app
安装参考http://blog.csdn.net/pzw_0612/article/details/46521965工具
http://www.cnblogs.com/huangjacky/archive/2012/03/28/2421866.htmlpost
用httpie模拟表单提交(post)this
>http -f post http://localhost:8000/app_dev.php/page/test name=lily
三、Response
<?php namespace Scource\WebBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;//注意不要引用错 use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; class DefaultController extends Controller { /** * @Route("/page/test1") */ public function test1Action(){
//不使用模板,直接输出内容或者跳转 //return new RedirectResponse('http://www.cnblogs.com/tianxintian22/');重定向 //return new JsonResponse(array('a'=>'abcdef'));返回json串 return new Response('11111111111'); } }
四、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') %}
<div class="flash-notice">
{{ flashMessage }}
</div>
{% endfor %}
五、Service -- 服务
程序架构的方式
做用:把特定事情的类或方法独立于当前代码单独存在并经过Service进行调用。
获取服务:$this->get();....