【问题标题】:Sylius : Catchable Fatal Error: Argument 1 passed to AppBundle\Controller\ProductController::__construct()Sylius:可捕获的致命错误:参数 1 传递给 AppBundle\Controller\ProductController::__construct()
【发布时间】:2016-10-31 17:24:24
【问题描述】:

我正在尝试覆盖 ProductController,我已遵循此文档: http://docs.sylius.org/en/stable/bundles/general/overriding_controllers.html 但异常不断出现:

可捕获的致命错误:传递给 Sylius\Bundle\ResourceBundle\Controller\ResourceController::__construct() 的参数 1 必须实现接口 Sylius\Component\Resource\Metadata\MetadataInterface,未给出,在 C:\wamp3\www\ 中调用sidratsoft_website\app\cache\dev\appDevDebugProjectContainer.php 在第 1382 行并定义

AppBundle/Controller/ProductController.php:

    <?php
namespace AppBundle\Controller;

use FOS\RestBundle\View\View;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sylius\Component\Resource\Metadata\MetadataInterface;
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Sylius\Component\Resource\ResourceActions;


class ProductController extends ResourceController
{


public function allProdSpecificTaxonAction(Request $request,$t){

    $locale = $this->get('sylius.context.locale')->getLocale();
    /** @var Taxon $taxon */
    $taxon = $this->get('sylius.repository.taxon')
    ->findByName('Honeywell',$locale);
    var_dump($taxon);
    exit;
}
}
?>

app/config/routing.yml:

app_bundle_product:
path: /products/cat/{taxon}
defaults:
    _controller: AppBundle:Product:allProdSpecificTaxonAction

app/config/config.yml:

sylius_product:
resources:
    product:
        classes:
            controller: AppBundle\Controller\ProductController

【问题讨论】:

    标签: sylius


    【解决方案1】:

    我想您不必在AppBundle/Resoures/config/services.yml 中将控制器注册为服务。当您扩展 ResourceController (这是完全正确的)时,它必须注入许多依赖项 - 幸运的是,您不必自己注入它们,因为 Sylius 将完成这项工作并自动注册控制器依赖注入。

    【讨论】:

    • 是的,我知道,但我发布了我所做的最后一次尝试,我不知道可能是什么问题,是否有解决方案或其他方法来覆盖产品控制器?
    • 这肯定不是正确的方法 - 根据我在答案中发布的原因。当您删除services.yml 中的服务声明时,您能否提供有关您遇到的错误的信息?
    • 它的相同异常:可捕获的致命错误:参数 1 传递给 Sylius\Bundle\ResourceBundle\Controller\ResourceController::__construct() 必须实现接口 Sylius\Component\Resource\Metadata\MetadataInterface,没有给出,在第 186 行的 C:\wamp3\www\sidratsoft_website\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Controller\ControllerResolver.php 中调用并定义
    【解决方案2】:

    我认为我已修复它,问题出在路由中的 _controller 属性中: 从此:

    app_bundle_product:
    path: /products/cat/{taxon}
    defaults:
        _controller: AppBundle:Product:allProdSpecificTaxonAction
    

    到:

    app_bundle_product:
        path: /products/cat/{taxon}
        defaults:
            _controller: sylius.controller.product:allProdSpecificTaxonAction
    

    【讨论】:

      猜你喜欢
      • 2017-02-21
      • 1970-01-01
      • 2014-11-11
      • 2012-03-13
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      相关资源
      最近更新 更多