如何登记表上增加一个字段? 我这样做:
\\src\UserBundle\Form\Type\RegistrationFormType.php
<?php
namespace UserBundle\Form\Type;
//use Symfony\Component\Form\AbstractType;
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);
$builder->add('realname');
}
public function getParent()
{
return 'fos_user_registration';
}
public function getName()
{
return 'app_user_registration';
}
}
\\src\UserBundle\Resources\config
services:
app_user.registration.form.type:
class: UserBundle\Form\Type\RegistrationFormType
arguments: [%fos_user.model.user.class%]
tags:
- { name: form.type, alias: app_user_registration }
\\src\UserBundle\Entity\User.php
namespace UserBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="web_user")
*/
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\Length(
* min=3,
* max=255,
* minMessage="The name is too short.",
* maxMessage="The name is too long.",
* groups={"Registration", "Profile"}
* )
*/
protected $realname;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set realname
*
* @param string $realname
* @return User
*/
public function setRealname($realname)
{
$this->realname = $realname;
return $this;
}
/**
* Get realname
*
* @return string
*/
public function getRealname()
{
return $this->realname;
}
}
\\src\UserBundle\Resources\config\services.yml
services:
app_user.registration.form.type:
class: UserBundle\Form\Type\RegistrationFormType
arguments: [%fos_user.model.user.class%]
tags:
- { name: form.type, alias: app_user_registration }
我不明白什么是缺少的结果是一个错误:未能加载类型“app_user_registration”请帮助我! 我认为,服务不找到