【发布时间】:2018-11-29 05:05:12
【问题描述】:
class DefaultController extends Controller
{
public function indexAction($page, $name) {
return $this->render('default/new.html.php'
// , array(
// $name => 'bob'
// )
);
}
}
new.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
routing.yml
app:
path: /dd
defaults:
_controller: AppBundle:Default:index
page: 1
name: "bob"
config.yml
framework:
# ...
templating:
engines: ['twig', 'php']
注意:我使用的是 ubuntu16.04 和 Symfony 3.4
【问题讨论】:
-
什么是错误信息?
-
Controller "AppBundle\Controller\DefaultController::indexAction()" 要求您为 "$name" 参数提供一个值。参数可以为空且未提供空值、未提供默认值或因为在此参数之后有一个非可选参数。
-
您将参数传递给操作,但您没有在路由中定义它。 symfony.com/doc/3.4/routing/extra_information.html
-
现在我得到了输出,但“名称”仍未显示 - 我的输出是“欢迎来到索引”
-
@newbie stackoverflow.com/questions/21279901/… 可能不支持短 php 标签?
标签: php html symfony model-view-controller twig