Explorar el Código

merged branch hhamon/template_reference_fix (PR #1342)

Commits
-------

7d09695 [FrameworkBundle] Simplified TemplateReference::getPath() method and added a unit test.
2616efb [FrameworkBundle] fixed TemplateRefence::getPath() when using namespaced controllers (i.e: AcmeBlogBundle\\Controller\\Admin\\PostController)

Discussion
----------

[FrameworkBundle] fixed TemplateRefence::getPath() when using namespaced

[FrameworkBundle] fixed TemplateRefence::getPath() when using namespaced controllers (i.e: AcmeBlogBundle\\Controller\\Admin\\PostController)
Fabien Potencier hace 14 años
padre
commit
48c1c47592

+ 2 - 1
src/Symfony/Bundle/FrameworkBundle/Templating/TemplateReference.php

@@ -40,7 +40,8 @@ class TemplateReference extends BaseTemplateReference
      */
     public function getPath()
     {
-        $controller = $this->get('controller');
+        $controller = str_replace('\\', '/', $this->get('controller'));
+
         $path = (empty($controller) ? '' : $controller.'/').$this->get('name').'.'.$this->get('format').'.'.$this->get('engine');
 
         return empty($this->parameters['bundle']) ? 'views/'.$path : '@'.$this->get('bundle').'/Resources/views/'.$path;

+ 28 - 0
src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateReferenceTest.php

@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
+
+use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
+use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
+
+class TemplateReferenceTest extends TestCase
+{
+    public function testGetPathWorksWithNamespacedControllers()
+    {
+        $reference = new TemplateReference('AcmeBlogBundle', 'Admin\Post', 'index', 'html', 'twig');
+
+        $this->assertSame(
+            '@AcmeBlogBundle/Resources/views/Admin/Post/index.html.twig',
+            $reference->getPath()
+        );
+    }
+}