我想在FosUser注册表中添加两个字段“Name”和“FirstName”,但它不起作用。 这是我的工作:
CulturalStore / UserBundle / Ressources / config / services.yml:
services:
cultural_store_user.registration.form.type:
class: CulturalStore\UserBundle\Form\Type\RegistrationFormType
arguments: [%cultural_store_user.model.user.class%]
tags:
- { name: form.type, alias: cultural_store_user_registration }
CulturalStore / UserBundle / Form / Type / RegistrationFormType:
<?php
namespace CulturalStore\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');
$builder->add('firstname');
}
public function getName()
{
return 'cultural_store_user_registration';
}
public function getFirstName()
{
return 'cultural_store_user_registration';
}
}
CulturalStore / UserBundle / Entity / User.php,我补充说:
/**
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="Entrez votre prénom.", groups={"Registration", "Profile"})
* @Assert\Length(
* min=3,
* max="255",
* minMessage="Prénom trop court.",
* maxMessage="Prénom trop long.",
* groups={"Registration", "Profile"}
* )
*/
protected $firstname;
/**
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="Entrez votre nom.", groups={"Registration", "Profile"})
* @Assert\Length(
* min=3,
* max="255",
* minMessage="Nom trop court.",
* maxMessage="Nom trop long.",
* groups={"Registration", "Profile"}
* )
*/
protected $name;
在app / config.yml中我有:
registration:
confirmation:
from_email:
address: "contact@culturalstore.com"
sender_name: "noreply - CulturalStore"
enabled: true
template: CulturalStoreUserBundle:Registration:email.txt.twig
form:
type: cultural_store_user_registration
但我有这个错误:
ParameterNotFoundException:服务“cultural_store_user.registration.form.type”依赖于不存在的参数“cultural_store_user.model.user.class”。
答案 0 :(得分:4)
服务文件中的这一行:arguments: [%cultural_store_user.model.user.class%]
应替换为arguments: [%fos_user.model.user.class%]
答案 1 :(得分:0)
添加到您的parameters.yml
parameters:
cultural_store_user.model.user.class: CulturalStore\UserBundle\Entity\User