可捕获的致命错误:参数1传递给ShopBundleControllerHomepageController::__c


Sylius : Catchable Fatal Error: Argument 1 passed to ShopBundleControllerHomepageController::__construct()

我试图覆盖HomepageController:indexAction从SyliusShopBundle传递一些数据到index.html.twig,但一个例外不断出现:

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

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/资源/config/services.yml:

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

AppBundle/资源/config/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 %}

您需要在服务定义中将模板引擎作为参数传递,内容如下:

services:
  app.custom_homepage_controller:
    class: AppBundle'Controller'CustomHomepageController
    arguments:
        - "@templating"
相关文章:
  • 没有找到相关文章