php扩展多配置文件,php – 将扩展配置文件实体添加到FOS UserBundle

如果您使用MySQL和php作为实体定义,那么您必须创建您的实体,如下所示:

// src/Acme/UserBundle/Entity/UserProfile.php

namespace Acme\UserBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;

use Doctrine\ORM\Mapping as ORM;

/**

* @ORM\Entity

* @ORM\Table(name="user_profile")

*/

class UserProfile extends BaseUser

{

/**

* @ORM\Id

* @ORM\Column(type="integer")

* @ORM\GeneratedValue(strategy="AUTO")

*/

protected $id;

/**

* @var string

*/

private $phone;

/**

* @var string

*/

private $language;

//....................

//Add all your properties here

public function __construct()

{

parent::__construct();

// your own logic

}

}

第二步是创建表单类型,询问您想要的字段:

// 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('phone');

$builder->add('language');

//...............

//Add all your properties here with $builder->add('property name')

}

public function getName()

{

return 'acme_user_registration';

}

}

现在您需要让捆绑包知道您要使用自定义表单:

# 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 }

最后一步是告诉FOSUserBundle它将使用您的表单类型而不是默认表单类型:

# app/config/config.yml

fos_user:

# ...

registration:

form:

type: acme_user_registration

资源:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值