Sylius:Catchable Fatal Error:参数1传递给ShopBundle \ Controller \ HomepageController :: __ construct()

时间:2016-10-12 16:21:17

标签: php symfony sylius symfony-2.8

我正在尝试覆盖SyliusShopBundle中的HomepageController:indexAction以将一些数据传递给index.html.twig,但会出现异常:

  

捕获致命错误:传递给AppBundle \ Controller \ CustomHomepageController :: __ construct()的参数1必须是Symfony \ Bundle \ FrameworkBundle \ Templating \ EngineInterface的实例,没有给出,在C:\ wamp3 \ www \ acme \中调用第1619行的app \ cache \ dev \ appDevDebugProjectContainer.php并定义了

的appbundle /控制器/ 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 /资源/配置/ services.yml:

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

的appbundle /资源/配置/ routing.yml中:

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

的appbundle /资源/视图/主页/ 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 个答案:

答案 0 :(得分:1)

您需要将模板引擎作为参数传递到服务定义中,其中包括:

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