Home > Enterprise >  Prestashop module with Symfony cant find the controller
Prestashop module with Symfony cant find the controller

Time:03-04

I am creating a module in Prestashop with Symfony but when I try to access my routes I get this error:

The controller for URI "/modules/youtuber/list" is not callable: Class "Myyoutubemc\Controller\YoutubeController"

Below is my controller it's located in: /modules/myyotubemc/src/controllers/youtubeController.php

<?php

namespace Myyoutubemc\Controller;

use GuzzleHttp\Subscriber\Redirect;
use Myyoutubemc\Entity\YoutubeComment;
use Myyoutubemc\Forms\YoutubeType;
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;


class YoutubeController extends FrameworkBundleAdminController
{

    public function demoAction()
    {
        return new Response('Hello Youtubers');
        // return $this->render('@Modules/your-module/templates/admin/demo.html.twig');
    }
    public function listAction()
    {
        $em = $this->getDoctrine()->getManager();
        $data = $em->getRepository(YoutubeComment::class)->findAll();
        return $this->render(
            '@Modules/myyoutubemc/templates/admin/list.html.twig',
            [
                'data' => $data
            ]
        );
    }

below is my routes located at my_module/config/routes.yml


youtube-list:
    path: youtuber/list
    methods: [GET]
    defaults:
      _controller: 'Myyoutubemc\Controller\YoutubeController::listAction'

How can I solve it Please ?.

Below is the error screenshot

enter image description here

CodePudding user response:

You have to install composer or just dump autoload classes.

See https://devdocs.prestashop.com/1.7/modules/concepts/controllers/admin-controllers/#example-using-psr-4-namespacing

  • Related