给定的api-platform字符串,必须是实体的类型
我猜想简单的问题,但是我无法使其正常工作:
im遇到此错误:app \ entity \ commands :: setServerId():参数#1($ serverid)必须是类型?app \ entity \ entity \ entity \ entity \ entity \ entity \ entity服务器,字符串给定
当我尝试通过api-platform添加新元素时,其工作正常工作:
,这是结果:
但是当我尝试通过邮递员或在我的控制器中进行Symfony Im在开始中提到错误时:
$commandDB = new Commands();
$commandDB->setCommand($command);
$commandDB->setStatusCode(1);
$commandDB->setOutput("added to DB");
$commandDB->setCreatedAt($date);
$commandDB->setServerID($serverid);
我的猜测Apiplatform是否能够采用'/api/server/1',并且明白这是IRI,它是实体,并且控制器不是,但是有任何方法可以解决吗?
谢谢
i have i guess simple problem, but i cant get it working properly:
Im getting this error: App\Entity\Commands::setServerID(): Argument #1 ($serverID) must be of type ?App\Entity\Servers, string given
And when i try to do add new element via api-platform its working correctly:
And here is result:
But when i try to do it via postman or in my controller in symfony im getting error mentioned in begining:
$commandDB = new Commands();
$commandDB->setCommand($command);
$commandDB->setStatusCode(1);
$commandDB->setOutput("added to DB");
$commandDB->setCreatedAt($date);
$commandDB->setServerID($serverid);
My guess is that apiplatform was able to take '/api/servers/1' and understand that this is IRI and it is entity, and controller is not, but is there's any way to fix it?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误说您必须通过一个实体,而不是ID。执行这样的操作:
将ManagerRegistry实例注入您的控制器
,然后获取服务器对象并将其设置为命令实体
The error says that you must pass in an entity, not an id. Do something like this:
Inject a ManagerRegistry instance into your controller
Then get your Servers object and set it into the Commands entity
那么,我在@harvey Dent的帮助下解决了
我的主要问题是让对象在setServerid()中传递;
Harvey建议
ManagerRegistry
,但我使用EntityManagerInterface
而不是因为它无法正常工作(无响应)。这是对我有用的代码的一部分:
再次感谢Harvey的想法!
Well then, i solved it with help of @Harvey Dent
my main problem was to get object to pass it in setServerID();
Harvey suggested
ManagerRegistry
but i usedEntityManagerInterface
instead becouse it was not working properly for me(null response).this is part of code that is working for me:
Thanks again Harvey for idea!