2017-09-22 14 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

相关问题