I'm learning Symfony3 framework. At now I've build project that contain two Entities: User and Catalog. Catalog entity is for additional Company data (company name, address, and so on) - it's like a business card. Single User (but not all) is connected only with one Business Card (Catalog entity) and that's why I've decided to use two separate entities. Some users have access e.g. to backend and other ones have possibility to add and manage their one Business Card. I want to allow user for fill in his Company details while he is registering. I'm using FOSUserBundle for User entity. At now I have registration form working but I'm stuck and need Your help with embed my CatalogType form.
CatalogType form:
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class CatalogType extends AbstractType { /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name') ->add('address') ->add('city') ->add('province') ->add('postcode') ->add('telephone') ->add('fax') ->add('mobile') ->add('email') ->add('webpage') ->add('misc') ; } public function getParent() { return 'FOS\UserBundle\Form\Type\RegistrationFormType'; } /** * {@inheritdoc} */ public function getBlockPrefix() { return 'app_user_registration'; } } User entity:
use Doctrine\ORM\Mapping as ORM; use FOS\UserBundle\Model\User as BaseUser; /** * User * * @ORM\Table(name="user") * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") */ class User extends BaseUser { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @var * * @ORM\OneToMany(targetEntity="Comment", mappedBy="user") */ private $comments; /** * @var * * @ORM\OneToOne(targetEntity="Catalog", mappedBy="user") */ private $catalog; public function __construct() { parent::__construct(); $this->comments = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Get id * * @return int */ public function getId() { return $this->id; } /** * Add comment * * @param \AppBundle\Entity\Comment $comment * * @return User */ public function addComment(\AppBundle\Entity\Comment $comment) { $this->comments[] = $comment; return $this; } /** * Remove comment * * @param \AppBundle\Entity\Comment $comment */ public function removeComment(\AppBundle\Entity\Comment $comment) { $this->comments->removeElement($comment); } /** * Get comments * * @return \Doctrine\Common\Collections\Collection */ public function getComments() { return $this->comments; } /** * Set catalog * * @param \AppBundle\Entity\Catalog $catalog * * @return User */ public function setCatalog(\AppBundle\Entity\Catalog $catalog = null) { $this->catalog = $catalog; return $this; } /** * Get catalog * * @return \AppBundle\Entity\Catalog */ public function getCatalog() { return $this->catalog; } } Catalog entity
<?php namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Catalog * * @ORM\Table(name="catalog") * @ORM\Entity(repositoryClass="AppBundle\Repository\CatalogRepository") */ class Catalog { // ... definition a lot of private variables ... /** * @var * * @ORM\OneToOne(targetEntity="User", inversedBy="catalog") * @ORM\JoinColumn(name="user_id", nullable=true) */ private $user; // ... /** * Set user * * @param \AppBundle\Entity\User $user * * @return Catalog */ public function setUser(\AppBundle\Entity\User $user = null) { $this->user = $user; return $this; } /** * Get user * * @return \AppBundle\Entity\User */ public function getUser() { return $this->user; } Services config file:
// app/config/services.yml services: app.form.registration: class: AppBundle\Form\CatalogType tags: - { name: form.type, alias: app_user_registration } When I'm trying to display register form under http://localhost:8000/register/ I'm getting an error:
Neither the property "name" nor one of the methods "getName()", "name()", "isName()", "hasName()", "__get()" exist and have public access in class "AppBundle\Entity\User".
I know where is the problem, but I don't know how to properly solve it so it would be great if somebody can help me where I should looking for solutions or how it should be solved. Thanks.