获取具有关系的实体时,FOSRestBundle 出现 HTTP 500 错误

HTTP 500 error with FOSRestBundle when getting an entity with relations

我从 FOSRestBundle 开始,当我获取没有关系的实体的值并将其显示在浏览器中时,我没有遇到任何问题。但是,当我尝试获取具有关系的实体时,它显示错误代码:500.

代码如下:

app/config/config.yml:

fos_rest:
    routing_loader:
        default_format: json
    param_fetcher_listener: true
    body_listener: true
    format_listener: true
    view:
        view_response_listener: 'force'

ApiRestBundle/Controller/UserController(这很好用)

   /**       
    * @return array       
    * @Rest\Get("/users")       
    * @Rest\View()       
    */ 

public function getUsersAction()
{
    $response = array();

    $em = $this->getDoctrine()->getManager(); 
    $users = $em->getRepository('CASUsuariosBundle:User')->findAll();

    $view = $this->view($users);

    return $this->handleView($view);
}

APIRestBunde/Controller/CategoryController(这行不通)

/**       
* @return array       
* @Rest\Get("/categories")       
* @Rest\View()       
*/ 

public function getCategoriesAction()
{
    $response = array();

    $em = $this->getDoctrine()->getManager(); 
    $categories = $em->getRepository('CASEventBundle:Category')->findAll();

    $view = $this->view($categories);

    return $this->handleView($view);   
}

错误代码:

{"error":{"code":500,"message":"Internal Server Error","exception":[{"message":"Notice: Undefined index: name","class":"Symfony\Component\Debug\Exception\ContextErrorException","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"C:\xampp\htdocs\CASPruebas\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\BasicEntityPersister.php","line":1758,"args":[]}...

你的问题解决起来有点复杂。

这个错误代码可能意味着很多不同的事情!

不过我觉得不直接是FOSRestBundle的问题。也许您的类别实体存在关系问题...

结果是什么:doctrine:schema:validate

编辑:如果您给我们完整的错误代码,也许解决起来会更简单。