PHP 使用 slim 框架时代码未被执行(注释掉)
PHP code not being executed (commented out) while using slim framework
我正在使用 slim 框架(路由等)并照亮数据库以在我的网页上输出数据,但它似乎不起作用,因为 php 代码在我在浏览器中加载网页时不断被注释掉(chrome).
我的路由(我也在用 slim-twig):
$app->get('/', function ($request, $response) {
return $this->get('view')->render($response, 'index.php');
});
php 我试图在 index.php
中呈现的代码
<?php
require "/vendor/autoload.php";
$tournaments = Tournaments::all();
phpinfo();
foreach ($tournaments as $tournament) {
echo $tournament->name;
}
?>
^ 此代码在浏览器代码视图中显示为 <!-- code -->
。
我是 php 框架的新手,因此不胜感激。
"View"层不负责取数据。相反,您应该传递所有数据以使用 3. 参数查看。
$app->get('/', function ($request, $response) {
$viewData = [
'tournaments' => Tournaments::all(),
];
return $this->get('view')->render($response, 'index.twig', $viewData);
});
index.twig
{% for tournament in tournaments %}
{{ tournament.name}}<br>
{% endfor %}
我正在使用 slim 框架(路由等)并照亮数据库以在我的网页上输出数据,但它似乎不起作用,因为 php 代码在我在浏览器中加载网页时不断被注释掉(chrome).
我的路由(我也在用 slim-twig):
$app->get('/', function ($request, $response) {
return $this->get('view')->render($response, 'index.php');
});
php 我试图在 index.php
中呈现的代码<?php
require "/vendor/autoload.php";
$tournaments = Tournaments::all();
phpinfo();
foreach ($tournaments as $tournament) {
echo $tournament->name;
}
?>
^ 此代码在浏览器代码视图中显示为 <!-- code -->
。
我是 php 框架的新手,因此不胜感激。
"View"层不负责取数据。相反,您应该传递所有数据以使用 3. 参数查看。
$app->get('/', function ($request, $response) {
$viewData = [
'tournaments' => Tournaments::all(),
];
return $this->get('view')->render($response, 'index.twig', $viewData);
});
index.twig
{% for tournament in tournaments %}
{{ tournament.name}}<br>
{% endfor %}