I am new to Symfony 2 Framework. I want to create an attachment for a relationship relationship of ManyToOne . I need the entity Address and AddressType
Address Object
namespace Webmuch\ProductBundle\Entity; use Doctrine\ORM\Mapping as ORM; class Address { private $id; private $line1; private $city; private $zip; private $phone; private $type; }
AddressType Addresses
namespace Webmuch\ProductBundle\Entity; use Doctrine\ORM\Mapping as ORM; class AddressType { private $id; private $title; }
Address controller
namespace Webmuch\ProductBundle\Controller; 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 Webmuch\ProductBundle\Entity\Address; use Webmuch\ProductBundle\Form\AddressType; class AddressController extends Controller { public function newAction() { $entity = new Address(); $form = $this->createForm(new AddressType(), $entity); return array( 'entity' => $entity, 'form' => $form->createView() ); } }
Form section
namespace Webmuch\ProductBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; class AddressType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder ->add('line1') ->add('line2') ->add('state') ->add('city') ->add('zip') ->add('phone') ->add('type') ; } }
I spent the whole day with this, and I tried many things, but I could not get it to work.
source share