Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony-将实体设置为多个实体_Php_Symfony_Json Api - Fatal编程技术网

Php Symfony-将实体设置为多个实体

Php Symfony-将实体设置为多个实体,php,symfony,json-api,Php,Symfony,Json Api,好的,伙计们,我问你们一个简单的问题,我如何设置一个不在参数中的实体 我正在尝试这种方法: $em_category = $this->getDoctrine()->getManager(); $em_category->getRepository('AppBundle:Category')->findOneBy(array('id' => ($request->get('id_category')))); $userInterest-

好的,伙计们,我问你们一个简单的问题,我如何设置一个不在参数中的实体

我正在尝试这种方法:

    $em_category = $this->getDoctrine()->getManager();
    $em_category->getRepository('AppBundle:Category')->findOneBy(array('id' => ($request->get('id_category'))));
    $userInterest->setUser($user);

    $userInterest->setCategory($em_category);
但当我这样做时,我有一个错误:

关联字段“AppBundle\Entity\UserInterest#$Category”的类型“AppBundle\Entity\Category”的预期值改为“条令\ORM\EntityManager”

那么,我怎样才能将我想要的类别设置为userinterest。。。?
Thx对于所有试图回答的问题:p

可变的
$em_类别
是您的实体管理器,该类执行数据库中的数据存储和检索。您需要使用它来获取类别,然后将该值传递给
setCategory
。像这样

$cat = $em_category->getRepository('AppBundle:Category')->findOneBy(array('id' => ($request->get('id_category'))));
$userInterest->setCategory($cat);