Skip to content
Advertisement

An exception has been thrown during the rendering of a template (“Controller not found:

After updating from Symfony 3.4 to 4.0 and verifying the operation, the following error occurred.
Do you have any idea?
I added the tride code to routes.yaml by referring to the post below, but it didn’t change.

Override a controller Symfony 3.4/4.0

Error

An exception has been thrown during the rendering of a template
("Controller not found: service "@AhiSpAdminBundle/Hq/Image/manager" does not exist.").

Resources/views/Hq/Staff/input.html.twig

    {# Image management dialog #}
    <div id="imageDialog" title="Image management">
        {{ render(controller("@AhiSpAdminBundle/Hq/Image/manager", {"modal": true})) }}
    </div>

routes.yaml

ahi_sp_admin:
    resource: "../src/Ahi/Sp/AdminBundle/Controller/"
    type:     annotation
    prefix:   /admin/
    schemes:  "%secure_scheme%"

#Tried code
ahi_sp_admin_hq_image_manager:
    path: /admin/hq/image/manager/
    defaults: { _controller: "@AhiSpAdminBundle/Hq/Image/manager" }

ImageController.php

    /**
     * Image management panel
     *
     * @Method("GET")
     * @Route("/manager")
     *
     * @Template("@AhiSpAdminBundle/Hq/Image/manager.html.twig")
     */
    public function managerAction(Request $request)
    {
        $routeParams = $request->get('_route_params');
        $uploadUrl = $this->generateUrl("ahi_sp_admin_hq_image_save");
        return array(
            'modal' => isset($routeParams["modal"]) ? $routeParams["modal"] : false,
            'form'  => $this->createUploadForm($uploadUrl)->createView(),
        );
    }

Advertisement

Answer

That’s not how you render a controller.

{{ render(controller(
        'App\Controller\ArticleController::recentArticles',
        { 'max': 3 }
    )) }}

It’s clear from the doc

To include the controller, you’ll need to refer to it using the standard string syntax for controllers (i.e. controllerNamespace::action):

https://symfony.com/doc/4.0/templating/embedding_controllers.html

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement