2017-05-11 8 views
0

\ ArrayAccessの実装していない私のカスタムユーザエンティティ:FosUserBundle私は、ユーザーのプロファイル編集するために、次にformTypeを行った

namespace AppUserBundle\Form\Type; 

use Symfony\Component\Form\AbstractType; 
use Symfony\Component\Form\FormBuilderInterface; 
use Symfony\Component\Form\DataTransformerInterface; 
use Symfony\Component\Form\Extension\Core\Type\TextareaType; 

class UserProfileFormType extends AbstractType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     //$builder->addViewTransformer($this->purifierTransformer); 
     $builder->add('name'); 
     $builder->add('surname'); 
     $builder->add('description',TextareaType::class); 
    } 

// public function getParent() 
// { 
//  return 'FOS\UserBundle\Form\Type\ProfileFormType'; 
// } 

    public function getBlockPrefix() 
    { 
     return 'app_user_registration'; 
    } 

    // For Symfony 2.x 
    public function getName() 
    { 
     return $this->getBlockPrefix(); 
    } 
} 

をそして、私はそのようなサービスとして設定しています

app_user.user_profile_form: 
    class: AppUserBundle\Form\Type 
    tags: 
     - { name: form.type, alias: app_user_registration } 

そしてconfig.ymlで次のconfigs:

fos_user: 
    ... 
    profile: 
    form: 
     type: AppUserBundle\Form\Type\UserProfileFormType 

私は01で見てきたようにgetParent()メソッドをオーバーライドしないだけでフォームを完全にオーバーライドできます。

If you don't want to reuse the fields added in FOSUserBundle by default, you can omit the getParent method and configure all fields yourself.

をしかし、私は次のエラーを取得する:ドキュメンテーションとして言う

Cannot read index "name" from object of type "AppUserBundle\Entity\User" because it doesn't implement \ArrayAccess.

AppUserBundle\Entity\Userは、次のコードを持っていることを覚えておいてください:

namespace AppUserBundle\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(name="user_image", type="string", length=255, nullable=true) 
    */ 
    private $userImage; 

    /** 
    * @ORM\Column(name="name", type="string", length=255, nullable=true) 
    * @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"} 
    *) 
    */ 
    private $name; 

    /** 
    * @ORM\Column(name="surname", type="string", length=255, nullable=true) 
    * @Assert\NotBlank(message="Please enter your name.", groups={"Registration", "Profile"}) 
    * @Assert\Length(
    *  min=3, 
    *  max=255, 
    *  minMessage="The surname is too short.", 
    *  maxMessage="The surname is too long.", 
    *  groups={"Registration", "Profile"} 
    *) 
    */ 
    private $surname; 

    /** 
    * @ORM\Column(name="description", type="string", length=1024, nullable=true) 
    */ 
    private $description; 

    public function __construct() 
    { 
     parent::__construct(); 
     // your own logic 
    } 

    public function setUserImage($imagepath) 
    { 
     $this->userImage=$imagepath; 
    } 

    public function functiongetUserImage() 
    { 
     return $this->userImage; 
    } 

    public function setName($name) 
    { 
     $this->name=strip_tags($name); 
    } 

    public function getName() 
    { 
     return $this->name; 
    } 

    public function setSurname($surname) 
    { 
     $this->surname=strip_tags($surname); 
    } 

    public function getSurname() 
    { 
     return $this->surname; 
    } 

    public function setDescription($description) 
    { 
     $this->description=$description; 
    } 

    public function getDescription() 
    { 
     return $this->description; 
    } 

私は任意のヘルプをappeciateます謎を解決するために

答えて

1

非常に古いですが、私もこのことに固執していました。私は誰かを助けることを願っています。 symfonyに、以下の関数を追加することで、あなたのカスタムクラスをあなたのカスタムクラスに使用していることを伝える必要があります。

$resolver->setDefaults(array(
     'data_class' => 'YourBundle\Entity\User', 
    )); 
関連する問題