为什么我得到这个错误? "无法启动会话,因为标题已经由""在第0行。"

时间:2016-07-04 12:45:37

标签: php backbone.js symfony

我不知道为什么我每次想要将新模型保存到我的收藏中时都会出现此错误。我的路线匹配,但每次都会出现错误。我有一个id,title,document和user_id的表。我只是想保存我的头衔。任何人都可以帮助我吗?

错误:无法启动会话,因为标题已由""在第0行。

PHP代码:

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use AppBundle\Entity\Document;
use Doctrine\ORM\Mapping as ORM;

class DocumentQueryController extends Controller
{  
    public function documentAction()
    {
        $id = $this->getUser()->getId();

    $em = $this->getDoctrine()->getManager();
    $documents = $em->getRepository('AppBundle:Document')->findAllOrderedById();
    $titles = array();

    foreach($documents as $document) 
    {
        $user_id = $document['user_id'];
        $title = $document['title'];

        if($user_id == $id)
        {
            $titles[] = $document;
        }             
    }

    return new JsonResponse($titles);

    //return new JsonResponse($document);
    //return new JsonResponse($documents);
    //dump(json_encode($documents));
    //return $this->render('default/doc.html.twig', array('documents' => $documents, 'id' => $id));
}

public function createAction(Request $request)
{
    $content = $this->get("request")->getContent();
    $json = json_decode($content);

    $id = $this->getUser()->getId();

    $document = new Document();
    $user_id = $id;

    $document->setTitle($request->get('title'));
    $document->setUserId($user_id);
    //$document->setBody($content);

    $em = $this->getDoctrine()->getManager();
    $em->persist($document);
    $em->flush();

    return new JsonResponse($document);
}
}

0 个答案:

没有答案