0
votes

I'm trying to override the HomepageController:indexAction from SyliusShopBundle to pass some data to the index.html.twig but an exception keep appearing:

Catchable Fatal Error: Argument 1 passed to AppBundle\Controller\CustomHomepageController::__construct() must be an instance of Symfony\Bundle\FrameworkBundle\Templating\EngineInterface, none given, called in C:\wamp3\www\acme\app\cache\dev\appDevDebugProjectContainer.php on line 1619 and defined

AppBundle/Controller/CustomHomepageController.php:

<?php
    namespace AppBundle\Controller;

    use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
    use Symfony\Component\HttpFoundation\Request;
    use Sylius\Bundle\ShopBundle\Controller\HomepageController as          baseHomepageController;


    class CustomHomepageController extends baseHomepageController
    {
    /**
    * @var EngineInterface
    */
    private $templatingEngine;

   /**
 * @return EngineInterface
 */
public function getTemplatingEngine()
{
    return $this->templatingEngine;
}

/**
 * @param EngineInterface $templatingEngine
 */
public function __construct(EngineInterface $templatingEngine)
{
    $this->templatingEngine = $templatingEngine;
}

/**
 * @param Request $request
 *
 * @return Response
 */
public function indexAction(Request $request)
{
    //var_dump($request);
    $s = "test";
    return $this->templatingEngine->renderResponse('SyliusShopBundle:Homepage:index.html.twig',array("data"=>$s));
}
}

AppBundle/Resources/config/services.yml:

    services:
      app.custom_homepage_controller:
        class: AppBundle\Controller\CustomHomepageController
          arguments:
            - "@templating"

AppBundle/Resources/config/routing.yml:

sylius_shop_homepage:
       path: /
        defaults:
         _controller: app.custom_homepage_controller:indexAction

AppBundle/Resources/views/Homepage/index.html.twig:

{% extends '@SyliusShop/layout.html.twig' %}

    {% block content %}
    <h1>{{ data }}</h1>

    <h2 class="ui horizontal section divider header">

    {{ 'sylius.ui.latest_products'|trans }}
    </h2>
    {% render(url('sylius_shop_partial_product_index_latest', {'count': 4,              'template': '@SyliusShop/Product/_simpleList.html.twig'})) %}

    {% include '@SyliusShop/Homepage/_promos.html.twig' %}

    {% include '@SyliusShop/Homepage/_grid.html.twig' %}
    {% endblock %}
1
This isn't nearly enough information to solve this. Please post the offending code.EJoshuaS - Reinstate Monica
Please post the code you are using to override the controller. You are probably missing one of the argumentsBrett
You will need to define your controller as a service and adjust your route accordingly: symfony.com/doc/current/controller/service.htmlCerad
I edited my post so you can see my code plz help . I did what you posted @ Cerad ,but still same issue :/Yosri Mekni

1 Answers

1
votes

You need to pass the templating engine as an argument in your service definition, something along those lines :

services:
  app.custom_homepage_controller:
    class: AppBundle\Controller\CustomHomepageController
    arguments:
        - "@templating"