这必须是一个简单的疏忽 - 为什么不将我的 entity_menus 参数注入StoreController?
这是我看到的错误:
捕获致命错误:参数1传递给AppBundle \ Controller \ Api \ Admin \ Common \ StoreController :: __ construct()必须是数组类型,没有给出
services.yml
的相关部分<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test Communicate with native app</title>
<script>
function startApp() {
var evt = document.createEvent("CustomEvent");
evt.initCustomEvent('myCustomEvent', true, false, "im information");
// fire the event
document.dispatchEvent(evt);
console.log("The button was clicked!");
}
</script>
</head>
<body>
<button type="button" onclick="startApp()" id="startApp">startApp</button>
</body>
</html>
控制器:
parameters:
entity_menus: [ 'manufacturers', 'vendors' ]
services:
app.admin.store_controller:
class: AppBundle\Controller\Api\Admin\Common\StoreController
arguments:
- '%entity_menus%'
答案 0 :(得分: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