symfony 4 php模板位置
请帮助,symfony 4找不到php模板 错误在于模板“::test/index.html.php”不存在 控制器:symfony 4 php模板位置,php,symfony,templates,symfony4,Php,Symfony,Templates,Symfony4,请帮助,symfony 4找不到php模板 错误在于模板“::test/index.html.php”不存在 控制器: namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; class TestController extends Controller { public fun
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class TestController extends Controller
{
public function number()
{
$number = mt_rand(0, 100);
// return new Response(
// '<html><body>Lucky number: '.$number.'</body></html>'
// );
return $this->render("test/number.html.php",
array('number' => $number));
}
function index() {
return $this->render("test/index.html.php");
}
}
namespace-App\Controller;
使用Symfony\Bundle\FrameworkBundle\Controller\Controller;
使用Symfony\Component\HttpFoundation\Response;
类TestController扩展控制器
{
公共职能编号()
{
$number=百万兰特(01100);
//返回新的响应(
//'幸运号码:'.$number'。'
// );
返回$this->render(“test/number.html.php”,
数组('number'=>$number));
}
函数索引(){
返回$this->render(“test/index.html.php”);
}
}
目录:
- 模板/
- 试验/
- index.html.php
- number.html.php
- 试验/
谢谢您应该使用composer for PHP引擎安装软件包。尝试清理缓存。检查“模板”目录的权限(755或777)
Symfony 4中不再使用带有bundle:directory:filename符号的快捷方式。而是使用相对于模板目录的实路径,或者对于bundle,使用带有@prefix的语法。有关更多信息:
如果您的错误发生在第三方捆绑包中,则此捆绑包无法与Symfony 4一起使用。然后,您可以分叉捆绑包并更改控制器中的模板符号。php模板的位置是src\Resources\Views您是否使用
twig
作为模板引擎?不,我使用的是php模板,已在配置中启用它可能重复,请看这篇文章:symfony 4中没有app/
文件夹,还有一个templates/
templates文件夹也不起作用,尝试了链接并更改了:return$this->render(“App:Test:index.html.php”)代码>