2017-09-22 13 views
1

我一直在閱讀並尋找解決方案,以解決此問題。但似乎我無法真正解決這個錯誤。我發現只有當我在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... 
+0

該解決方案是否解決了您的問題? –

回答

3

這樣稱呼它,其他實體:{{ form_widget(form.firstName) }}

在您的表單中,這是firstName,而不是first_name。相同的姓氏中間名...

+0

當我嘗試調用標籤'{{'profile.show.firstName'}}'時,會出現這種情況,只顯示** form.user.firstName **。我認爲這個問題確實存在於表單構建器中。我不確定它是什麼。我也無法顯示「{{app.user.firstName}}」和所有其他新實體。 – WashichawbachaW

+0

是什麼?這與您之前的問題完全不同,或者您忘了在帖子中解釋某些內容。你從未提過'{{'profile.show.firstName'}}或'{{app.user.firstName}}'... –

+0

對不起,我的不好。這是表格的標籤。就像'{{'profile.show.username'| trans({},'FOSUserBundle')}}'&'{{'profile.show.email'| trans({},'FOSUserBundle')}}'。我忘記了跨部分。也許我現在真的很累。我想我可以自己修復它。我以前遇到過這個。 – WashichawbachaW

相關問題