创建新 Twig 模板后清除缓存时出错
Error when clearing cache after creating new Twig template
我使用的是ORO平台框架
每当我创建一个新视图并在我的控制器中重定向到它时,它就会工作。
但是当我使用 cache:clear
、rm -rf var/cache/*
或 bin/console --env="prod" cache:clear
清除缓存时。页面停止工作,出现以下错误:
An exception has been thrown during the rendering of a template ("The "CompanyName\Bundle\TestBundle\Controller\TestController::index" controller is not a valid "class::method" string.")
我可以使用以前未使用过的名称创建一个新的控制器 + 视图,它会做同样的事情。
我也可以在新项目中复制这个问题。
我的控制器:
class TestController extends AbstractController
{
/**
* @Route("/test", name="test")
*/
public function index()
{
return $this->render('test/index.html.twig', [
'controller' => 'TestController',
]);
}
}
我的模板:
{% extends 'base.html.twig' %}
{% block title %}Hello TestController!{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper">
<h1>Hello {{ controller_name }}! ✅</h1>
This friendly message is coming from:
<ul>
<li>Your controller at <code><a href="{{ '/home/name/PhpstormProjects/test_project/src/CompanyName/Bundle/TestBundle/Controller/TestController.php'|file_link(0) }}">src/CompanyName/Bundle/TestBundle/Controller/TestController.php</a></code></li>
<li>Your template at <code><a href="{{ '/home/name/PhpstormProjects/test_project/templates/test/index.html.twig'|file_link(0) }}">templates/test/index.html.twig</a></code></li>
</ul>
</div>
{% endblock %}
控制器中的方法必须以 'Action' 结尾,例如 indexAction
我使用的是ORO平台框架
每当我创建一个新视图并在我的控制器中重定向到它时,它就会工作。
但是当我使用 cache:clear
、rm -rf var/cache/*
或 bin/console --env="prod" cache:clear
清除缓存时。页面停止工作,出现以下错误:
An exception has been thrown during the rendering of a template ("The "CompanyName\Bundle\TestBundle\Controller\TestController::index" controller is not a valid "class::method" string.")
我可以使用以前未使用过的名称创建一个新的控制器 + 视图,它会做同样的事情。
我也可以在新项目中复制这个问题。
我的控制器:
class TestController extends AbstractController
{
/**
* @Route("/test", name="test")
*/
public function index()
{
return $this->render('test/index.html.twig', [
'controller' => 'TestController',
]);
}
}
我的模板:
{% extends 'base.html.twig' %}
{% block title %}Hello TestController!{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper">
<h1>Hello {{ controller_name }}! ✅</h1>
This friendly message is coming from:
<ul>
<li>Your controller at <code><a href="{{ '/home/name/PhpstormProjects/test_project/src/CompanyName/Bundle/TestBundle/Controller/TestController.php'|file_link(0) }}">src/CompanyName/Bundle/TestBundle/Controller/TestController.php</a></code></li>
<li>Your template at <code><a href="{{ '/home/name/PhpstormProjects/test_project/templates/test/index.html.twig'|file_link(0) }}">templates/test/index.html.twig</a></code></li>
</ul>
</div>
{% endblock %}
控制器中的方法必须以 'Action' 结尾,例如 indexAction