コード例 #1
0
 /**
  * This is just an example howto use barcodes and to display them
  * @param Request $request
  * @return Response
  */
 public function playgroundAction(Request $request)
 {
     $types = BarcodeTypes::getTypes();
     $errors = array();
     $form = $this->container->get('form.factory')->createBuilder('form')->add('text')->add('type', 'choice', array('empty_value' => 'Choose an option', 'choices' => $types))->getForm();
     $webfile = false;
     if ($request->getMethod() == 'POST') {
         $form->submit($request);
         $data = $form->getData();
         $text = $data['text'];
         $type = $data['type'];
         if ($type) {
             try {
                 $bmanager = $this->container->get('mopa_barcode.barcode_service');
                 $webfile = $bmanager->get($type, $text);
             } catch (\Exception $e) {
                 $errors[] = $e->getMessage();
             }
         } else {
             $errors[] = "Please select a option";
         }
         if (count($errors)) {
             $webfile = false;
         }
     }
     return $this->container->get('templating')->renderResponse('MopaBarcodeBundle:Barcode:playground.html.twig', array('form' => $form->createView(), 'barcode_url' => $webfile, 'errors' => $errors));
 }
コード例 #2
0
 /**
  * @param ImagineInterface $imagine
  * @param $kernelcachedir
  * @param $kernelrootdir
  * @param $webdir
  * @param $webroot
  * @param Logger $logger
  */
 public function __construct(ImagineInterface $imagine, $kernelcachedir, $kernelrootdir, $webdir, $webroot, Logger $logger)
 {
     $this->types = BarcodeTypes::getTypes();
     $this->imagine = $imagine;
     $this->kernelcachedir = $kernelcachedir;
     $this->kernelrootdir = $kernelrootdir;
     $this->webdir = $webdir;
     $this->webroot = $webroot;
     $this->logger = $logger;
 }