我使用Symfony 2.8.x和FOSUserBundle。FOSUserBundle extend RegisterForm
我嘗試擴大我的用戶喜歡用姓氏和名字幾場......我不喜歡它的文件說 https://symfony.com/doc/master/bundles/FOSUserBundle/overriding_forms.html
當我嘗試以下信息註冊來
Neither the property "name" nor one of the methods "getName()", "name()", "isName()", "hasName()", "__get()" exist and have public access in class "AppBundle\Entity\User"
這是我的註冊類
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name');
}
public function getParent()
{
return 'FOS\UserBundle\Form\Type\RegistrationFormType';
// Or for Symfony < 2.8
// return 'fos_user_registration';
}
public function getBlockPrefix()
{
return 'app_user_registration';
}
// For Symfony 2.x
public function getName()
{
return $this->getBlockPrefix();
}
}
,這是我的用戶類別
<?php
// src/AppBundle/Entity/User.php
namespace AppBundle\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="fos_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 $name;
/**
* @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 $firstname;
/**
* @ORM\Column(type="integer")
*/
protected $mentorid;
public function __construct()
{
parent::__construct();
// your own logic
}
}
有人可以幫我解決這個問題嗎?
此致敬禮
,我打算給二傳手加入到user.php的和RegistrationType.php見http://symfony.com/doc/current/doctrine.html#generating-getters-and-setters。兩者都沒有工作或創建一個新的錯誤。 – Anutrof
這是一個典型的錯誤,這意味着您在實體類中沒有該字段的getter。 因此,在「AppBundle \ Entity \ User」中添加公共getter,如果您的代碼不起作用,請在此處發佈完整的實體類代碼。 –
我重新啓動服務器,現在它看起來像它的工作,但我不能再註冊。 – Anutrof