2 回答
TA贡献2012条经验 获得超12个赞
几天前我找到了问题的答案。我把自己复杂化了,就像这样:
首先,您在 Templates 文件夹中创建视图。
$params 引用 URL。例如:
校友是捆绑

AlumneController.php
然后在 AlumneController.php 中输入不带 .html 的视图名称,然后使用$this->twig = "name_Of_The_View.html";
<?php
class AlumneController extends Controller{
public function process($params)
{
/*var_dump($params);
die();*/
if(empty($params[0])){
$this->getAlumne();
/*echo $usuari = $_SESSION["username"];*/
}else if(isset($params[0]) && $params[0] == "instruccions"){
$this->twig = "instruccions.html";
/*echo $usuari = $_SESSION["username"];*/
}else if(isset($params[0]) && $params[0] == "resultats"){
$this->twig = "resultats.html";
/*echo $usuari = $_SESSION["username"];*/
}
}
public function getAlumne(){
$this->twig = "alumne.html";
}
}
校友.html
在按钮或链接中,您用于访问您在其中写入路径的页面<a href="bundle/view_name">Instruccions</a>
<a class="mdl-navigation__link" href="alumne/instruccions">Instruccions</a>
<a class="mdl-navigation__link" href="alumne/resultats">Resultats</a>AlumneController.php
然后在 AlumneController.php 中输入不带 .html 的视图名称,然后使用$this->twig = "name_Of_The_View.html";
<?php
class AlumneController extends Controller{
public function process($params)
{
/*var_dump($params);
die();*/
if(empty($params[0])){
$this->getAlumne();
/*echo $usuari = $_SESSION["username"];*/
}else if(isset($params[0]) && $params[0] == "instruccions"){
$this->twig = "instruccions.html";
/*echo $usuari = $_SESSION["username"];*/
}else if(isset($params[0]) && $params[0] == "resultats"){
$this->twig = "resultats.html";
/*echo $usuari = $_SESSION["username"];*/
}
}
public function getAlumne(){
$this->twig = "alumne.html";
}
}
校友.html
在按钮或链接中,您用于访问您在其中写入路径的页面<a href="bundle/view_name">Instruccions</a>
<a class="mdl-navigation__link" href="alumne/instruccions">Instruccions</a>
<a class="mdl-navigation__link" href="alumne/resultats">Resultats</a>
TA贡献1872条经验 获得超4个赞
我认为您正在寻找的是Twig 的 API。
更具体地说,您需要下面的行来渲染模板,并在数组中传递一些参数:
echo $template->render(['the' => 'variables', 'go' => 'here']);
如果您使用 PHP 将某些内容“打印”到浏览器的最快方式是echo,请不要犹豫使用它。
- 2 回答
- 0 关注
- 159 浏览
添加回答
举报
