Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.73 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. namespace JStout\MainBundle\Controller;
  4.  
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller,
  6.     Sensio\Bundle\FrameworkExtraBundle\Configuration as Extra,
  7.     JStout\MainBundle\Component\Form\FormHandlerInterface,
  8.     JStout\MainBundle\Entity\User,
  9.     JStout\MainBundle\Entity\Vendor,
  10.     JStout\MainBundle\Entity\Location,
  11.     JStout\MainBundle\Form\Vendor\SignupType,
  12.     JStout\MainBundle\Form\Vendor\SignupHandler;
  13.  
  14.  
  15. /**
  16.  * @Extra\Route("/vendor")
  17.  */
  18. class VendorController extends Controller
  19. {
  20.     /**
  21.      * @Extra\Route(name="vendor_index")
  22.      * @Extra\Template()
  23.      */
  24.     public function indexAction()
  25.     {
  26.         return array();
  27.     }
  28.  
  29.     /**
  30.      * @Extra\Route("/sign-up", name="vendor_signup")
  31.      * @Extra\Template()
  32.      */
  33.     public function signupAction()
  34.     {
  35.         // initialize new vendor
  36.         $vendor = new Vendor();
  37.  
  38.         if (($user = $this->get('request')->getSession()->get('user')) instanceOf User) {
  39.             $vendor->setOwner($user);
  40.         }
  41.  
  42.         // get vendor signup form
  43.         $form  = $this->get('form.factory')->create(new SignupType(), $vendor);
  44.        
  45.         // get form handler for vendor form
  46.         $formHandler = $this->get('form.handler')->create(new SignupHandler(), $form);
  47.  
  48.         // extra data for form handler
  49.         $extras = array(
  50.             'encoderFactory' => $this->get('security.encoder_factory'),
  51.             'aclProvider' => $this->get('security.acl.provider')
  52.         );
  53.  
  54.         // redirect if form submission was valid
  55.         if (($vendor = $formHandler->process($extras)) instanceOf Vendor) {
  56.             return $this->redirect($this->generateUrl('vendor_index'));
  57.         }
  58.  
  59.         return array(
  60.             'form' => $form->createView()
  61.         );
  62.     }
  63. }