[英]Using HTML.PHP instead of html.twig - not working
class DefaultController extends Controller
{
public function indexAction($page, $name) {
return $this->render('default/new.html.php'
// , array(
// $name => 'bob'
// )
);
}
}
新的.html.php
<p>Welcome to the index <?= $name; ?></p>
當我使用此代碼時,它返回一條錯誤消息。
但,
<p>Welcome to the index {{ name }}
這使我返回正確的輸出。
我想使用.html.php
而不是.html.twig
我正在瀏覽這個https://symfony.com/doc/3.4/templating/PHP.html
路由.yml
app:
path: /dd
defaults:
_controller: AppBundle:Default:index
page: 1
name: "bob"
配置文件
framework:
# ...
templating:
engines: ['twig', 'php']
注意:我使用的是 ubuntu16.04 和 Symfony 3.4
根據Symfony文檔在本地嘗試:
/**
* @Route("/test", name="test_route")
*/
public function test()
{
return $this->render(
'test.html.php',
[
'test_var' => 'Hello test',
]
);
}
我的test.html.php
:
<?php
echo $test_var;
這將輸出Hello test
。
PS:試過get_defined_vars();
,應該在那里看到變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.