Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>SOLVED.</strong></p> <p>I seem to should not have use the collection form.<br> And I seem to should use to "<code>-&gt;add('profile', new ProfileType())</code>". </p> <p>hope this helps</p> <hr> <p>Entity/Profile.php</p> <pre><code>namespace My\UserBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass="My\UserBundle\Repository\UserRepository") */ class Profile { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\Column(type="string", length=255, nullable=true) */ protected $website; // .... and other profile /** * @ORM\OneToOne(targetEntity="User", mappedBy="profile", cascade={"persist", "merge", "remove"}) */ protected $user; // .... } </code></pre> <p>Entity/User.php</p> <pre><code>// ... /** * @ORM\OneToOne(targetEntity="Profile", inversedBy="user", cascade={"persist", "merge", "remove"}) * @ORM\JoinColumn(referencedColumnName="id") */ protected $profile; public function setProfile(Profile $profile) { $this-&gt;profile = $profile; } public function getProfile() { return $this-&gt;profile; } </code></pre> <p>Controller/ProfileController</p> <pre><code>public function editAction() { $em = $this-&gt;container-&gt;get('doctrine')-&gt;getManager(); $own = $this-&gt;container-&gt;get('security.context')-&gt;getToken()-&gt;getUser(); $user = $em-&gt;getRepository('MyUserBundle:User')-&gt;find_one_with_info($own); //=&gt; Left join profile table if (!is_object($user) || !$user instanceof UserInterface) { throw new AccessDeniedException('This user does not have access to this section.'); } if (! $user-&gt;getProfile()) $user-&gt;setProfile(new Profile()); $form = $this-&gt;container-&gt;get('fos_user.profile.form'); $formHandler = $this-&gt;container-&gt;get('fos_user.profile.form.handler'); $process = $formHandler-&gt;process($user); // ... </code></pre> <p>Form/Type/ProfileType</p> <pre><code>// ... public function buildForm(FormBuilderInterface $builder, array $options) { $builder -&gt;add('website', 'text', array('required' =&gt; false)) // ... and other profile ; } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver-&gt;setDefaults(array( 'data_class' =&gt; 'My\UserBundle\Entity\Profile', )); } // ... </code></pre> <p>Form/Type/ProfileFormType</p> <pre><code>// ... protected function buildUserForm(FormBuilderInterface $builder, array $options) { $builder -&gt;add('username', null, array('label' =&gt; 'form.username', 'translation_domain' =&gt; 'FOSUserBundle')) -&gt;add('profile', new ProfileType()) ; } // ... </code></pre> <p>View/Profile/edit_content.html.twig</p> <pre><code>// ... &lt;div&gt; {{ form_errors(form.profile.website) }} &lt;/div&gt; &lt;div&gt; &lt;label&gt;Website:&lt;/label&gt; {{ form_widget(form.profile.website) }} &lt;/div&gt; // ... and other profile &lt;div&gt; {{ form_errors(form.current_password) }} &lt;/div&gt; &lt;div&gt; {{ form_label(form.current_password) }} {{ form_widget(form.current_password) }} &lt;/div&gt; {{ form_widget(form) }} // ... </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload