简体   繁体   中英

Error when clearing cache after creating new Twig template

I am using the ORO platform framework.

Whenever I create a new view and redirect to it in my controller it works.

But when I clear my cache with the cache:clear , rm -rf var/cache/* or bin/console --env="prod" cache:clear . The page stops working, I get the following error:

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.")

I can create a new controller + view with a name that I haven't used before and it will do the same thing.

I can replicate this issue in a new project too.

My controller:

class TestController extends AbstractController
{
    /**
     * @Route("/test", name="test")
     */
    public function index()
    {
        return $this->render('test/index.html.twig', [
            'controller' => 'TestController',
        ]);
    }
}

My template:

{% 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM