默认的form包含注册用户,修改用户信息,修改密码等等,如果想对User追加属性,或者追加追加一部分功能,那就需要重写form。
- 创建如下的ORM User类,追加属性name
<?php // src/Acme/UserBundle/Entity/User.php use FOS\UserBundle\Entity\User as BaseUser; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; class User extends BaseUser { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(type="string", length=255) * * @Assert\NotBlank(message="Please enter your name.", groups={"Registration", "Profile"}) * @Assert\MinLength(limit="3", message="The name is too short.", groups={"Registration", "Profile"}) * @Assert\MaxLength(limit="255", message="The name is too long.", groups={"Registration", "Profile"}) */ protected $name; // ... }
* 默认情况下,新用户注册时会调用注册验证配置文件,如果需要对name属性做验证,请确保验证文件已经加入name属性。
- 例如追加name属性,可以进行下边修改
<?php // src/Acme/UserBundle/Form/Type/RegistrationFormType.php namespace Acme\UserBundle\Form\Type; use Symfony\Component\Form\FormBuilderInterface; use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType; class RegistrationFormType extends BaseType { public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); // add your custom field $builder->add('name'); } public function getName() { return 'acme_user_registration'; } }
- 修改service.yml配置文件
# src/Acme/UserBundle/Resources/config/services.yml services: acme_user.registration.form.type: class: Acme\UserBundle\Form\Type\RegistrationFormType arguments: [%fos_user.model.user.class%] tags: - { name: form.type, alias: acme_user_registration }
- 修改config.yml配置文件
# app/config/config.yml fos_user: # ... registration: form: type: acme_user_registration
相关推荐
symfony-console-form, 为控制台命令输入使用Symfony窗体 控制台窗体By Noback 这个包包含一个Symfony包和一些工具,允许你使用Symfony表单类型来定义和交互处理来自的用户输入。安装composer require ...
Symfony2 + FOSUserBundle 这是一个基本的 Symfony2 框架 v2.1.7,安装并配置了流行的 FOSUserBundle 以与 MySQL 一起使用。
Symfony控制台表格马蒂亚斯·诺巴克(Matthias ...安装composer require matthiasnoback/symfony-console-form 在Symfony应用程序的内核中启用Matthias\SymfonyConsoleForm\Bundle\SymfonyConsoleFormBundle 。 <?...
This day is about the project specifications.They are the same as in the original Jobeet tutorial so you can see a more detailed description and a mockup design ...Symfony2 Jobeet Day 2_ The Project PDF
艾尔郡迷你基于 Symfony 2 框架AyrshireMinis ( ) 网站
Symfony2 技术类帮助图书,Symfony2 技术类帮助图书,Symfony2 技术类帮助图书,
symfony2常规操作,这是平时研究时积累下来的文档。
symfony-jsonapi, 用于 Symfony 2和 Symfony 3的JSON API变压器包 Symfony json对于 Symfony 2和 Symfony 3 安装工具使用情况创建映射输出API响应JSON API请求JSON API响应与NelmioApiDocBund
国内symfony2的框架资料较少,很多都是symfony1.x的资料,当symfony2的框架改变非常大,为方便你我,分享一下学习过程中看过的资料,这个vblog的实例非常不错。
这是本人第一次尝试写教程,忘各位多多捧场
symfony2创建实体命令 四步骤
Symfony2 常用命令和基本使用方法,简单的说明,和实例。
在本书里,你将了解如何使用symfony建立Web应用程序。本书分成五篇:“基础知识”篇,包含所有的基本概念和开始symfony的基本知识;“核心架构”篇,讲述模型视图控制器(MVC)在symfony中的实现,以及如何用这样的...
ClankBundle, 一个Symfony2包,用于 Ratchet web socket服务器 ClankBundleClank是一个Symfony2包,旨在在一个易于使用的应用程序架构中集成 web socket功能。socket.io 一样,它提供了服务器端和客户端代码,确保你...
最牛叉的PHP框架,没有之一。 《精通Symfony2》,实乃phper居家旅行,吹牛装象的 必备神器!
争吵简单的 Symfony2 Scrum 项目管理#设置 composer install-- 学说数据库架构: php app/console doctrine:schema:update --force——创建管理员用户: ...ADMIN)——设置应用程序: php app/console app:setup——
著名的PHP开发框架 symfony是什么?symfony能做什么?使用symfony需要掌握哪些知识?此文档会解答这些问题。
Symfony应用程序文档生成器
Symfony2 Jobeet Day 1:Starting up the Project PDF Today we will setup the development environment,install Symfony2 and display a page of the application in a web browser. Symfony2 PHP Framework
Symfony是PHP框架中最强大的,完整实现了MVC三层结构,封装了所有东西,包括建立项目、应用、模块、刷新... Symfony绝对是开发大型复杂项目的首选,使用Symfony,将大大节约开发成本,并且多人协作的时,不会出现问题。