symfony form表单和安装FOFUserBundle


 

1.下载composer.phar 

[root#localhost opt]# curl -sS https://getcomposer.org/installer | php

2.把composer.phar移动到环境下让其变成可执行

[root@localhost opt]# mv composer.phar /usr/local/bin/composer

3.测试

[root@localhost opt]# composer -V
Composer version 1.0-dev (8775c948956c9e0e0a5fd723cd84c94b3ea3d7e9) 2015-07-01 09:29:53
composer config repo.packagist composer https://packagist.phpcomposer.com

 
composer require friendsofsymfony/user-bundle "~2.0@dev"
出现ok就代表下载好了   FOFUserBundle扩展主要是用在登录,注册上面
安装FOFUserBundle需要七个步骤
 见官网http://symfony.com/doc/current/bundles/FOSUserBundle/index.html
 
2.form表单POST接收数据  http://symfony.com/doc/current/components/http_foundation.html
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;

 
public function getAction(Request $request)
    {
$id=$request->query->get('id');   //获取的是地址栏的id
return $this->render("HttpBundle:Default:get.html.twig",['id'=>$id]);
    }
function postAction(Request $request){
$user=$request->request->get('user');  //user是form表单的值
return new Response('name:'.$user);
}
function formAction(Request $request){
return $this->render('HttpBundle:Default:form.html.twig');
}

 

<!doctype html> //form.html.twig
<html>
<head>
<meta charset="utf-8" />
<title>form</title>
</head>
<body>
<form action="{{ path('http_post') }}" method="post">
<input type="text" name="user" />
<input type="submit" />
</form>
</body>
</html>

评论 抢沙发