【问题标题】:Sylius : Catchable Fatal Error: Argument 1 passed to ShopBundle\Controller\HomepageController::__construct()Sylius:可捕获的致命错误:参数 1 传递给 ShopBundle\Controller\HomepageController::__construct()
【发布时间】:2017-02-21 13:11:57
【问题描述】:

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

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

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 %}

【问题讨论】:

  • 这还不足以解决这个问题。请发布违规代码。
  • 请发布您用来覆盖控制器的代码。您可能缺少其中一个论点
  • 您需要将控制器定义为服务并相应地调整您的路由:symfony.com/doc/current/controller/service.html
  • 我编辑了我的帖子,所以你可以看到我的代码请帮助。我做了你在@Cerad 发布的内容,但仍然是同样的问题:/

标签: php symfony sylius symfony-2.8


【解决方案1】:

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

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

【讨论】:

  • thx ,现在又出现了一个异常:在 SyliusShopBundle 中渲染模板期间抛出了异常(“没有一个链接的路由器能够生成路由:找不到路由 'sylius_shop_login'”): Homepage\Menu:_security.html.twig 在第 7 行。我将 CustomHomepageConroller:indexAction 中的渲染行更改为 from :
  • 现在出现了另一个异常:在 SyliusShopBundle:Homepage\ 中渲染模板期间引发了异常(“没有一个链接的路由器能够生成路由:找不到路由 'sylius_shop_login'”)菜单:_security.html.twig 在第 7 行
  • 您是否包含了店铺路线?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-11-11
  • 2012-03-13
  • 2017-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-23
相关资源
最近更新 更多