我一直在閱讀並尋找解決方案,以解決此問題。但似乎我無法真正解決這個錯誤。我發現只有當我在FOS/UserBundle/Form/Type/RegistrationFormType中添加表單時,這是它在樹枝中顯示的唯一時間。我想我有一些問題,需要我的UserBundle/Form/RegistrationFormType。 需要幫助。Symfony - 既不存在屬性「first_name」也不存在其中一種方法,並且可以在類「Symfony Component Form FormView」中公開訪問
我使用FOSUserBundle
這裏是我的用戶類:
<?php
namespace UserBundle\Entity;
use FOS\UserBundle\Entity\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(name="first_name", type="string", length=255, nullable=false)
* @Assert\NotBlank(message="Please enter your first name", groups={"Registration", "Profile"})
*/
protected $firstName;
/**
* @ORM\Column(name="middle_name", type="string", length=255, nullable=false)
* @Assert\NotBlank(message="Please enter your middle name", groups={"Registration", "Profile"})
*/
protected $middleName;
/**
* @ORM\Column(name="last_name", type="string", length=255, nullable=false)
* @Assert\NotBlank(message="Please enter your last name", groups={"Registration", "Profile"})
*/
protected $lastName;
/**
* @ORM\Column(name="position", type="string", length=255, nullable=false)
* @Assert\NotBlank(message="Please enter your position/title", groups={"Registration", "Profile"})
*/
protected $position;
/**
* @ORM\Column(name="gender", type="string", length=255, nullable=false)
* @Assert\NotBlank(message="Please chose your gender", groups={"Registration", "Profile"})
*/
protected $gender;
/**
* @ORM\Column(name="birth_date", type="string", nullable=true)
*/
protected $birthDate;
/**
* @ORM\Column(name="address", type="string", length=255, nullable=true)
*/
protected $address;
/**
* @ORM\Column(name="school", type="string", length=255, nullable=true)
*/
protected $school;
/**
* @ORM\Column(name="hired_date", type="string", nullable=false)
*/
protected $hiredDate;
/**
* @ORM\Column(name="end_date", type="string", nullable=false)
*/
protected $endDate;
// Change the targetEntity path if you want to create the group
/**
* @ORM\ManyToMany(targetEntity="UserBundle\Entity\Group")
* @ORM\JoinTable(name="fos_user_user_group",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
*)
*/
protected $groups;
public function __construct()
{
parent::__construct();
}
/**
* @return String
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @return String
*/
public function getMiddleName()
{
return $this->middleName;
}
/**
* @return String
*/
public function getLastName()
{
return $this->lastName;
}
/**
* @return String
*/
public function getPosition()
{
return $this->position;
}
/**
* @return String
*/
public function getGender()
{
return $this->gender;
}
/**
* @return String
*/
public function getBirthDate()
{
return $this->birthDate;
}
/**
* @return String
*/
public function getAddress()
{
return $this->address;
}
/**
* @return String
*/
public function getSchool()
{
return $this->school;
}
/**
* @return String
*/
public function getHiredDate()
{
return $this->hiredDate;
}
/**
* @return String
*/
public function getEndDate()
{
return $this->endDate;
}
/**
* @param String $firstName
* @return User
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
return $this;
}
/**
* @param String $middleName
* @return User
*/
public function setMiddleName($middleName)
{
$this->middleName = $middleName;
return $this;
}
/**
* @param String $lastName
* @return User
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
return $this;
}
/**
* @param String $position
* @return User
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
/**
* @param String $gender
* @return User
*/
public function setGender($gender)
{
$this->gender = $gender;
return $this;
}
/**
* @param String $birthDate
* @return User
*/
public function setBirthDate($birthDate)
{
$this->birthDate = $birthDate;
return $this;
}
/**
* @param String $address
* @return User
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* @param String $school
* @return User
*/
public function setSchool($school)
{
$this->school = $school;
return $this;
}
/**
* @param String $hiredDate
* @return User
*/
public function setHiredDate($hiredDate)
{
$this->hiredDate = $hiredDate;
return $this;
}
/**
* @param String $endDate
* @return User
*/
public function setEndDate($endDate)
{
$this->endDate = $endDate;
return $this;
}
}
這裏是我的RegistrationFormType:
<?php
namespace UserBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstName', 'text', array('label' => 'form.first_name', 'translation_domain' => 'FOSUserBundle'))
->add('middleName', 'text', array('label' => 'form.middle_name', 'translation_domain' => 'FOSUserBundle'))
->add('lastName', 'text', array('label' => 'form.last_name', 'translation_domain' => 'FOSUserBundle'))
->add('position', 'text', array('label' => 'form.position', 'translation_domain' => 'FOSUserBundle'))
->add('gender', 'text', array('label' => 'form.gender', 'translation_domain' => 'FOSUserBundle'))
->add('birthDate', 'date', array('label' => 'form.birth_Date', 'translation_domain' => 'FOSUserBundle'))
->add('address', 'text', array('label' => 'form.address', 'translation_domain' => 'FOSUserBundle'))
->add('school', 'text', array('label' => 'form.school', 'translation_domain' => 'FOSUserBundle'))
->add('hiredDate', 'date', array('label' => 'form.hired_date', 'translation_domain' => 'FOSUserBundle'))
->add('endDate', 'text', array('label' => 'form.end_date', 'translation_domain' => 'FOSUserBundle'))
;
}
public function getParent()
{
return 'fos_user_registration';
}
public function getName()
{
return 'user_registration';
}
}
這裏是我的services.yml:
services:
app.form.registration:
class: UserBundle\Form\RegistrationFormType
tags:
- { name: form.type, alias: user_registration }
這裏是我的config.yml:
fos_user:
db_driver: orm
firewall_name: main
user_class: UserBundle\Entity\User
group:
group_class: UserBundle\Entity\Group
profile:
form:
type: UserBundle\Form\ProfileFormType
registration:
form:
name: user_registration
這裏是我的枝杈:我想呼籲所有我做
{{ form_widget(form.first_name) }}
{{ form_widget(form.last_name) }}
{{ form_widget(form.middle_name) }}
// and so on...
該解決方案是否解決了您的問題? –