Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Garethp\PhotosBundle\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Garethp\PhotosBundle\Entity\Photo;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
- use Symfony\Component\HttpFoundation\Request;
- class DefaultController extends Controller
- {
- public function indexAction()
- {
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- try
- {
- $repo = $this->getDoctrine()->getRepository('GarethpPhotosBundle:Photo');
- $photos = $repo->createQueryBuilder('p')
- ->addOrderBy('p.timestamp', 'DESC')
- ->addOrderBy('p.id', 'DESC')
- ->getQuery()
- ;
- $photos = $photos->getResult();
- return $this->render('GarethpPhotosBundle:Default:index.html.twig', array('photos'=>$photos));
- }
- catch(Exception $e)
- {
- var_dump($e);
- }
- }
- public function uploadAction(Request $request)
- {
- $photo = new Photo();
- $form = $this->createFormBuilder(null, array('csrf_protection'=>false))
- ->add('file', 'file', array(
- 'multiple'=>true,
- 'attr'=>array(
- 'accept'=>'image/*',
- 'capture'=>'camera',
- 'multiple'=>'multiple'
- )
- ))
- ->add('upload', 'submit')
- ->getForm();
- $form->handleRequest($request);
- if($form->isValid())
- {
- $em = $this->getDoctrine()->getManager();
- $data = $form->getData();
- $files = $data['file'];
- foreach($files as $file)
- {
- $photo = new Photo();
- $photo->setFile($file);
- $em->persist($file);
- }
- // $em->persist($photo);
- $em->flush();
- return $this->redirect($this->generateUrl('garethp_photos_homepage'));
- }
- return $this->render('GarethpPhotosBundle:Default:upload.html.twig', array('form'=>$form->createView()));
- }
- public function videoAction()
- {
- return $this->render('GarethpPhotosBundle:Default:video.html.twig');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement