2016-12-15 51 views
0

這必須是一個簡單的疏忽 - 爲什麼我的entity_menus參數被注入StoreController?Symfony 3 - FOSRestBundle - 注入對服務的依賴

這是我看到的錯誤:

Catchable Fatal Error: Argument 1 passed to AppBundle\Controller\Api\Admin\Common\StoreController::__construct() must be of the type array, none given

services.yml的相關部分

parameters: 
    entity_menus: [ 'manufacturers', 'vendors' ] 

services: 
    app.admin.store_controller: 
     class: AppBundle\Controller\Api\Admin\Common\StoreController 
     arguments: 
      - '%entity_menus%' 

控制器:

class StoreController extends FOSRestController 
{ 

    private $entityMenus; 

    public function __construct(Array $entityMenus) 
    { 
     $this->entityMenus = $entityMenus; 
    } 

回答

0

我更新services.yml像這樣設置服務容器:

app.admin.store_controller: 
    class: AppBundle\Controller\Api\Admin\Common\StoreController 
    arguments: ['%entity_menus%'] 
    calls: 
     - [setContainer, ["@service_container"]] 

感謝:https://stackoverflow.com/a/19283476/2182349

我更新routing_rest.yml使用的服務名稱和類:

app_admin_common_store_menu: 
    type:  rest 
    class: AppBundle\Controller\Api\Admin\Common\StoreController 
    resource: app.admin.store_controller 
    name_prefix: app_admin_api_store_ 
    prefix: /api/store 

感謝:https://github.com/FriendsOfSymfony/FOSRestBundle/issues/990