2015-09-23 49 views
2

我是symfony的新手,我想使用PHP模板引擎。以下是我爲了使其工作而遵循的步驟。在config.yml在symfony中找不到PHP模板

templating: 
    engines: ['twig', 'php'] 

1.Enabled PHP模板引擎2.Defined在routing.yml中

hello: 
    path:  /hello/{name} 
    defaults: { _controller: AppBundle:Hello:index, name:World } 

3.Created HelloController中我控制路徑和默認值。 php

namespace AppBundle\Controller; 

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 
use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\Request; 

class HelloController extends Controller 
{ 
    public function indexAction($name) 
    { 
     return $this->render('hello/name.html.php', array(
      'name'=>$name 
     )); 
    } 
} 

4.Created視圖\程序\資源\意見\你好\ name.html.php

<!-- app/Resources/views/Hello/name.html.php --> 
Hello <?php echo $name ?>! 

,但是當我試圖訪問http://127.0.0.1:8000/hello,它讓我看到下面的錯誤

模板「hello/name.html.php」不存在。

500內部服務器錯誤 - InvalidArgumentException

我改變的模板文件夾名稱從「你好」到「你好」,但還是同樣的錯誤。也試圖渲染這樣的模板

return $this->render(
    'AppBundle:Hello:index.html.php', 
    array('name' => $name) 
); 

但沒有運氣,我必須在這裏丟失的東西。有人能指導我正確的方向嗎?

注:你好/ name.html.twig加載沒有任何錯誤

謝謝!

+0

http://symfony.com/doc/current/cookbook/templating/PHP.html 這個頁面說,你需要使用註釋: /** * @Template(發動機=「PHP 「) */ 你試過 用它? – Grzegorz

+0

文件夾名稱應爲'hello'並在更改後清除緩存。 – malcolm

回答

3

如果你的模板在app /資源/視圖/你好/文件夾,你應該使用這個符號:

$response = $this->render(':Hello:name.html.php'); 

如果你想將其移動到的src /的appbundle /資源/視圖/你好文件夾,然後使用

$response = $this->render('AppBundle:Hello:name.html.php');