Explorar el Código

Use Symfony addFlash method

Sullivan SENECHAL hace 10 años
padre
commit
8d7e3694b1
Se han modificado 2 ficheros con 13 adiciones y 3 borrados
  1. 9 3
      Controller/CRUDController.php
  2. 4 0
      Tests/Controller/CRUDControllerTest.php

+ 9 - 3
Controller/CRUDController.php

@@ -1230,12 +1230,18 @@ class CRUDController extends Controller
      *
      *
      * @param string $type
      * @param string $type
      * @param string $message
      * @param string $message
+     *
+     * @TODO Remove this method when bumping requirements to Symfony >= 2.6
      */
      */
     protected function addFlash($type, $message)
     protected function addFlash($type, $message)
     {
     {
-        $this->get('session')
-             ->getFlashBag()
-             ->add($type, $message);
+        if (method_exists('Symfony\Bundle\FrameworkBundle\Controller\Controller', 'addFlash')) {
+            parent::addFlash($type, $message);
+        } else {
+            $this->get('session')
+                ->getFlashBag()
+                ->add($type, $message);
+        }
     }
     }
 
 
     /**
     /**

+ 4 - 0
Tests/Controller/CRUDControllerTest.php

@@ -295,6 +295,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
                     return true;
                     return true;
                 }
                 }
 
 
+                if ($id == 'session') {
+                    return true;
+                }
+
                 return false;
                 return false;
             }));
             }));