Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace PimBundle\Controller\Admin;
- use PimBundle\Entity\Image;
- use PimBundle\Form\Admin\UploadImageType;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\HttpFoundation\JsonResponse;
- use Symfony\Component\HttpFoundation\Request;
- /**
- * Class ImageController
- * @package PimBundle\Controller\Admin
- */
- class ImageController extends Controller
- {
- /**
- * @param Request $request
- * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
- */
- public function indexAction(Request $request)
- {
- $em = $this->getDoctrine()->getManager();
- $images = $em->getRepository('PimBundle:Image')->getAll();
- $image = new Image();
- $form = $this->createForm(new UploadImageType(), $image, array(
- 'action' => $this->generateUrl('pim_admin_image_index'),
- 'method' => 'POST',
- ));
- $form->handleRequest($request);
- if ($form->isValid()) {
- $em->persist($image);
- $em->flush();
- return $this->redirectToRoute('pim_admin_image_index');
- }
- return $this->render('PimBundle:Admin:imagesList.html.twig', array(
- 'images' => $images,
- 'form' => $form->createView(),
- ));
- }
- public function listAction()
- {
- $em = $this->getDoctrine()->getManager();
- $images = $em->getRepository('PimBundle:Image')->getAll();
- $response = array();
- foreach ($images as $image) {
- $response[] = array(
- 'title' => (
- $image->getTitle() ?
- 'no title (' . date_format($image->getCreatedAt(), 'H:i M j') . ')' :
- $image->getTitle()
- ),
- 'value' => $image->getSrc(),
- );
- }
- return new JsonResponse($response);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement