首页 文章

500内部服务器错误 - 传递的参数必须是类类型,但整数给 - symfony2

提问于
浏览
0

我在symfony2应用程序中创建了两个类之间的关系 . 它的设计使得tableB与tableA相关,我在tableA表中输入数据(作为超级实体),在我的控制器中,我使用json来发布一个帖子,将数据插入tableB表 . 来自tableB的引用外键需要一个整数,但是当我尝试从邮递员发帖时,我得到了这个奇怪的错误

{
"message": "Expected value of type "\myBundle\Entity\TableA" for association field "\myBundle\Entity\Platforms#$dataValue", got "integer" instead.",
"class": "Doctrine\ORM\ORMInvalidArgumentException",

这是我从邮递员发帖的json格式

{
"id": 6,
"variable": false,
"variable": true,
"variable": true,
"variable": true,
"variable": false,
"variable": true,
"variable": true,
"variable": true,
"variable": false,
"variable": false,
"variable": true,
"fkValue":3 //area of challenge
}

在我的实体类中,我有这段代码片段

/**
     * 
     *
     * @param \MyBundle\Entity\TableA $dataValue 
     * @return Platforms
     */
    public function setValue(\Api3Bundle\Entity\TableA $dataValue  = null)
    {
        $this->dataValue  = $dataValue ;

        return $this;
    }

================EDITED==================

这就是我如何将控制器中的数据插入TableB到TableA的外键字段

//getting the value from request
$variable = $request->get('variable');

//setting the value for persistence
$data->setValue($variable);//area of challenge
  $em = $this->getDoctrine()->getManager();
$em = $this->getDoctrine()->getManager();
  $em->persist($data);

我不知道我是否在正确的轨道上,但有些人可以告诉我如何使用邮递员的json将数据插入外键字段 . 非常感谢

1 回答

相关问题