title: Symfony2 - Pulling data from database and show in forms
body: <p>I want to show the data on my forms but I am not able to do so.</p>
  
  <p><strong>Here is my profile.php under userbundle:</strong></p>
  
  <pre><code> &lt;?php
  
  namespace project\UserBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Profile
   *
   * @ORM\Table(name="project_profiles")
   * @ORM\Entity
   * @ORM\HasLifecycleCallbacks
   */
  class Profile
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var \project\UserBundle\Entity\User
       *
       * @ORM\OneToOne(targetEntity="\project\UserBundle\Entity\User", inversedBy="profile")
       */
      private $user;
  
      /**
       * @var string
       *
       * @ORM\Column(name="first_name", type="string")
       */
      private $firstName;
  
      /**
       * @var string
       *
       * @ORM\Column(name="last_name", type="string")
       */
      private $lastName;
  
      /**
       * @var string
       *
       * @ORM\Column(name="address1", type="string")
       */
      private $address1;
  
      /**
       * @var string
       *
       * @ORM\Column(name="address2", type="string")
       */
      private $address2;
  
      /**
       * @var string
       *
       * @ORM\Column(name="city", type="string")
       */
      private $city;
  
      /**
       * @var string
       *
       * @ORM\Column(name="state", type="string")
       */
      private $state;
  
      /**
       * @var string
       *
       * @ORM\Column(name="zipcode", type="string")
       */
      private $zipcode;
  
      /**
       * @var string
       *
       * @ORM\Column(name="country", type="string")
       */
      private $country;
  
      /**
       * @var integer
       *
       * @ORM\Column(name="client_api_delay", type="integer")
       */
      private $clientApiDelay;
  
      /**
       * @var \DateTime
       *
       * @ORM\Column(name="created_at", type="datetime")
       */
      private $createdAt;
  
      /**
       * @var \DateTime
       *
       * @ORM\Column(name="updated_at", type="datetime", nullable=true)
       */
      private $updatedAt;
  
      /**
       * Get id
       *
       * @return integer
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set firstName
       *
       * @param string $firstName
       * @return Profile
       */
      public function setFirstName($firstName)
      {
          $this-&gt;firstName = $firstName;
  
          return $this;
      }
  
      /**
       * Get firstName
       *
       * @return string
       */
      public function getFirstName()
      {
          return $this-&gt;firstName;
      }
  
      /**
       * Set lastName
       *
       * @param string $lastName
       * @return Profile
       */
      public function setLastName($lastName)
      {
          $this-&gt;lastName = $lastName;
  
          return $this;
      }
  
      /**
       * Get lastName
       *
       * @return string
       */
      public function getLastName()
      {
          return $this-&gt;lastName;
      }
  
      /**
       * Set address1
       *
       * @param string $address1
       * @return Profile
       */
      public function setAddress1($address1)
      {
          $this-&gt;address1 = $address1;
  
          return $this;
      }
  
      /**
       * Get address1
       *
       * @return string
       */
      public function getAddress1()
      {
          return $this-&gt;address1;
      }
  
      /**
       * Set address2
       *
       * @param string $address2
       * @return Profile
       */
      public function setAddress2($address2)
      {
          $this-&gt;address2 = $address2;
  
          return $this;
      }
  
      /**
       * Get address2
       *
       * @return string
       */
      public function getAddress2()
      {
          return $this-&gt;address2;
      }
  
      /**
       * Set city
       *
       * @param string $city
       * @return Profile
       */
      public function setCity($city)
      {
          $this-&gt;city = $city;
  
          return $this;
      }
  
      /**
       * Get city
       *
       * @return string
       */
      public function getCity()
      {
          return $this-&gt;city;
      }
  
      /**
       * Set state
       *
       * @param string $state
       * @return Profile
       */
      public function setState($state)
      {
          $this-&gt;state = $state;
  
          return $this;
      }
  
      /**
       * Get state
       *
       * @return string
       */
      public function getState()
      {
          return $this-&gt;state;
      }
  
      /**
       * Set zipcode
       *
       * @param string $zipcode
       * @return Profile
       */
      public function setZipcode($zipcode)
      {
          $this-&gt;zipcode = $zipcode;
  
          return $this;
      }
  
      /**
       * Get zipcode
       *
       * @return string
       */
      public function getZipcode()
      {
          return $this-&gt;zipcode;
      }
  
      /**
       * Set country
       *
       * @param string $country
       * @return Profile
       */
      public function setCountry($country)
      {
          $this-&gt;country = $country;
  
          return $this;
      }
  
      /**
       * Get country
       *
       * @return string
       */
      public function getCountry()
      {
          return $this-&gt;country;
      }
  
      /**
       * Set clientApiDelay
       *
       * @param integer $clientApiDelay
       * @return Profile
       */
      public function setClientApiDelay($clientApiDelay)
      {
          $this-&gt;clientApiDelay = $clientApiDelay;
  
          return $this;
      }
  
      /**
       * Get clientApiDelay
       *
       * @return integer
       */
      public function getClientApiDelay()
      {
          return $this-&gt;clientApiDelay;
      }
  
      /**
       * Set createdAt
       *
       * @param \DateTime $createdAt
       * @return Profile
       */
      public function setCreatedAt($createdAt)
      {
          $this-&gt;createdAt = $createdAt;
  
          return $this;
      }
  
      /**
       * Get createdAt
       *
       * @return \DateTime
       */
      public function getCreatedAt()
      {
          return $this-&gt;createdAt;
      }
  
      /**
       * Set createdAt to NOW
       *
       * @return Profile
       * @ORM\PrePersist
       */
      public function setCreatedAtNow()
      {
          $this-&gt;createdAt = new \DateTime();
  
          return $this;
      }
  
      /**
       * Set updatedAt
       *
       * @param \DateTime $updatedAt
       * @return Profile
       */
      public function setUpdatedAt($updatedAt)
      {
          $this-&gt;updatedAt = $updatedAt;
  
          return $this;
      }
  
      /**
       * Get updatedAt
       *
       * @return \DateTime
       */
      public function getUpdatedAt()
      {
          return $this-&gt;updatedAt;
      }
  
      /**
       * Set updatedAt to NOW
       *
       * @return Profile
       * @ORM\PreUpdate
       */
      public function setUpdatedAtNow()
      {
          $this-&gt;updatedAt = new \DateTime();
  
          return $this;
      }
  
      /**
       * Set user
       *
       * @param \project\UserBundle\Entity\User $user
       * @return Profile
       */
      public function setUser(\project\UserBundle\Entity\User $user = null)
      {
          $this-&gt;user = $user;
  
          return $this;
      }
  
      /**
       * Get user
       *
       * @return \project\UserBundle\Entity\User
       */
      public function getUser()
      {
          return $this-&gt;user;
      }
  }
  </code></pre>
  
  <p><strong>My ProfileController.php file:</strong></p>
  
  <pre><code>&lt;?php
  
  namespace project\UserBundle\Controller;
  
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  use project\UserBundle\Entity\Profile;
  use project\UserBundle\Form\ProfileType;
  
  /**
   * Profile controller.
   *
   * @Route("/admin/profile")
   */
  class ProfileController extends Controller
  {
      /**
       * Lists all Profile entities.
       *
       * @Route("/", name="admin_profile")
       * @Method("GET")
       * @Template()
       */
      public function indexAction()
      {
          $em = $this-&gt;getDoctrine()-&gt;getManager();
  
          $entities = $em-&gt;getRepository('projectUserBundle:Profile')-&gt;findAll();
  
          return array(
              'entities' =&gt; $entities,
          );
      }
  
      /**
       * Creates a new Profile entity.
       *
       * @Route("/", name="admin_profile_create")
       * @Method("POST")
       * @Template("projectUserBundle:Profile:new.html.twig")
       */
      public function createAction(Request $request)
      {
          $entity  = new Profile();
          $form = $this-&gt;createForm(new ProfileType(), $entity);
          $form-&gt;bind($request);
  
          if ($form-&gt;isValid()) {
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              $em-&gt;persist($entity);
              $em-&gt;flush();
  
              return $this-&gt;redirect($this-&gt;generateUrl('admin_profile_show', array('id' =&gt; $entity-&gt;getId())));
          }
  
          return array(
              'entity' =&gt; $entity,
              'form'   =&gt; $form-&gt;createView(),
          );
      }
  
      /**
       * Displays a form to create a new Profile entity.
       *
       * @Route("/new", name="admin_profile_new")
       * @Method("GET")
       * @Template()
       */
      public function newAction()
      {
          $entity = new Profile();
          $form   = $this-&gt;createForm(new ProfileType(), $entity);
  
          return array(
              'entity' =&gt; $entity,
              'form'   =&gt; $form-&gt;createView(),
          );
      }
  
      /**
       * Finds and displays a Profile entity.
       *
       * @Route("/{id}", name="admin_profile_show")
       * @Method("GET")
       * @Template()
       */
      public function showAction($id)
      {
          $em = $this-&gt;getDoctrine()-&gt;getManager();
  
          $entity = $em-&gt;getRepository('projectUserBundle:Profile')-&gt;find($id);
  
          if (!$entity) {
              throw $this-&gt;createNotFoundException('Unable to find Profile entity.');
          }
  
          $deleteForm = $this-&gt;createDeleteForm($id);
  
          return array(
              'entity'      =&gt; $entity,
              'delete_form' =&gt; $deleteForm-&gt;createView(),
          );
      }
  
      /**
       * Displays a form to edit an existing Profile entity.
       *
       * @Route("/{id}/edit", name="admin_profile_edit")
       * @Method("GET")
       * @Template()
       */
      public function editAction($id)
      {
          $em = $this-&gt;getDoctrine()-&gt;getManager();
  
          $entity = $em-&gt;getRepository('projectUserBundle:Profile')-&gt;find($id);
  
          if (!$entity) {
              throw $this-&gt;createNotFoundException('Unable to find Profile entity.');
          }
  
          $editForm = $this-&gt;createForm(new ProfileType(), $entity);
          $deleteForm = $this-&gt;createDeleteForm($id);
  
          return array(
              'entity'      =&gt; $entity,
              'edit_form'   =&gt; $editForm-&gt;createView(),
              'delete_form' =&gt; $deleteForm-&gt;createView(),
          );
      }
  
      /**
       * Edits an existing Profile entity.
       *
       * @Route("/{id}", name="admin_profile_update")
       * @Method("PUT")
       * @Template("projectUserBundle:Profile:edit.html.twig")
       */
      public function updateAction(Request $request, $id)
      {
          $em = $this-&gt;getDoctrine()-&gt;getManager();
  
          $entity = $em-&gt;getRepository('projectUserBundle:Profile')-&gt;find($id);
  
          if (!$entity) {
              throw $this-&gt;createNotFoundException('Unable to find Profile entity.');
          }
  
          $deleteForm = $this-&gt;createDeleteForm($id);
          $editForm = $this-&gt;createForm(new ProfileType(), $entity);
          $editForm-&gt;bind($request);
  
          if ($editForm-&gt;isValid()) {
              $em-&gt;persist($entity);
              $em-&gt;flush();
  
              return $this-&gt;redirect($this-&gt;generateUrl('admin_profile_edit', array('id' =&gt; $id)));
          }
  
          return array(
              'entity'      =&gt; $entity,
              'edit_form'   =&gt; $editForm-&gt;createView(),
              'delete_form' =&gt; $deleteForm-&gt;createView(),
          );
      }
  
      /**
       * Deletes a Profile entity.
       *
       * @Route("/{id}", name="admin_profile_delete")
       * @Method("DELETE")
       */
      public function deleteAction(Request $request, $id)
      {
          $form = $this-&gt;createDeleteForm($id);
          $form-&gt;bind($request);
  
          if ($form-&gt;isValid()) {
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              $entity = $em-&gt;getRepository('projectUserBundle:Profile')-&gt;find($id);
  
              if (!$entity) {
                  throw $this-&gt;createNotFoundException('Unable to find Profile entity.');
              }
  
              $em-&gt;remove($entity);
              $em-&gt;flush();
          }
  
          return $this-&gt;redirect($this-&gt;generateUrl('admin_profile'));
      }
  
      /**
       * Creates a form to delete a Profile entity by id.
       *
       * @param mixed $id The entity id
       *
       * @return Symfony\Component\Form\Form The form
       */
      private function createDeleteForm($id)
      {
          return $this-&gt;createFormBuilder(array('id' =&gt; $id))
              -&gt;add('id', 'hidden')
              -&gt;getForm()
          ;
      }
  }
  </code></pre>
  
  <p>I have declared my entities under Resources/Profile/show.html and everything works:
  For example for address I have:            </p>
  
  <pre><code>&lt;th&gt;Address2&lt;/th&gt;
  &lt;td&gt;{{ entity.address2 }}&lt;/td&gt;
  </code></pre>
  
  <p>My problem is I have another bundle called ShowBundle and I want to show those entities on that bunddle. For e.g When I call {{ entity.address2 }} on that bundle to show my address it shows me that: <em>(variable "entity" doesnt exist)</em></p>
  
  <p>How I can display those profile entities on the twig forms in another bundle, in my case ShowBundle?</p>
  
  <p>Thanks a lot</p>