Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.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中的Json_数组_Php_Doctrine Orm_Doctrine_Symfony - Fatal编程技术网

Php symfony中的Json_数组

Php symfony中的Json_数组,php,doctrine-orm,doctrine,symfony,Php,Doctrine Orm,Doctrine,Symfony,我试图在我的数据库中插入json数据,由于某些原因,我无法在数据库中插入数据 这是我的密码 namespace ScheduleBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Response; //Json Response use Symfony\Component\HttpFoundation\JsonR

我试图在我的数据库中插入json数据,由于某些原因,我无法在数据库中插入数据

这是我的密码

namespace ScheduleBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;

//Json Response
use Symfony\Component\HttpFoundation\JsonResponse;

//Class Controller
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

//Request
use Symfony\Component\HttpFoundation\Request;

use ScheduleBundle\Entity\schedule;

class ApiController extends Controller
{
  /**
   * @Route("/api/{week}")
   */
  public function roosterApi(Request $request, $week)
  {
    //
    //
    // print_r($rooster);
    //
    // echo 'Rooster: ' . $dataRooster->getSchedule();
    $rooster = array('week' => '1');

    $roosterConnection = $this->get('doctrine')->getRepository('ScheduleBundle:schedule', 'schedule');
    $dataRooster = $roosterConnection->findOneByStudentId('36838');


    $dataRooster->setSchedule($rooster);

    $out = array('1' => $week);

    return new JsonResponse($out, 200, array('Content-Type' => 'application/json'));
  }
}
这是我的实体

namespace ScheduleBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * schedule
 *
 * @ORM\Table(name="schedule")
 * @ORM\Entity(repositoryClass="ScheduleBundle\Repository\scheduleRepository")
 */
class schedule
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="student_id", type="string", length=20)
     */
    private $studentId;

    /**
     * @var array
     *
     * @ORM\Column(name="schedule", type="json_array")
     */
    private $schedule;


    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set studentId
     *
     * @param string $studentId
     *
     * @return schedule
     */
    public function setStudentId($studentId)
    {
        $this->studentId = $studentId;

        return $this;
    }

    /**
     * Get studentId
     *
     * @return string
     */
    public function getStudentId()
    {
        return $this->studentId;
    }

    /**
     * Set schedule
     *
     * @param array $schedule
     *
     * @return schedule
     */
    public function setSchedule($schedule)
    {
        $this->schedule = $schedule;

        return $this;
    }

    /**
     * Get schedule
     *
     * @return array
     */
    public function getSchedule()
    {
        return $this->schedule;
    }
}
我正在使用doctrine和symfony 3.0

编辑:添加了我文件中的所有代码。我也没有得到任何错误。
添加了实体代码

您需要告诉条令保留(并刷新)您的更改

$entityManager = $this->get('doctrine')->getEntityManager();
$roosterConnection = $this->get('doctrine')->getRepository('ScheduleBundle:schedule', 'schedule');
$dataRooster = $roosterConnection->findOneByStudentId('36838');

$dataRooster->setSchedule($rooster);

$entityManager->persist($dataRooster);
$entityManager->flush();

您需要告诉Dority坚持(并刷新)您的更改

$entityManager = $this->get('doctrine')->getEntityManager();
$roosterConnection = $this->get('doctrine')->getRepository('ScheduleBundle:schedule', 'schedule');
$dataRooster = $roosterConnection->findOneByStudentId('36838');

$dataRooster->setSchedule($rooster);

$entityManager->persist($dataRooster);
$entityManager->flush();

请在插入数据的位置添加代码。是否有任何错误?ScheduleBundle:schedule实体的映射元数据可能会有所帮助。@JimL我没有收到任何错误,这就是我插入您忘记保存的数据的方式。请看给出的答案,它为您提供了解决方案,但您应该在这里询问之前至少查看以下内容:)请在插入数据的位置添加代码。是否有任何错误?ScheduleBundle:schedule实体的映射元数据可能会有所帮助。@JimL我没有收到任何错误,这就是我插入您忘记保存的数据的方式。请看给出的答案,它为您提供了解决方案,但您应该在这里询问之前至少看一下:)谢谢您的回答我认为它解决了我的问题,但它给了我下一个错误在链配置的命名空间StudentsBundle\Entity中找不到类“ScheduleBundle\schedule”\Entity检查拼写,另外,类名通常应该是大写的,我不确定这是否是您的问题的原因,因为我总是让所有的类名都以大写字母开头。错误告诉您问题所在,因此请自问,“为什么在
配置的命名空间StudentsBundle\Entity
中找不到'ScheduleBundle\Entity\schedule'?”谢谢你的回答我认为它解决了我的问题,但它给了我下一个错误在链配置的名称空间中找不到类“ScheduleBundle\Entity\schedule”StudentsBundle\Entity检查拼写,并且类名通常应为大写,我不确定这是否是你的问题的原因,因为我总是让所有的类名都以大写字母开头。错误告诉您问题所在,因此请自问,“为什么在
配置的命名空间StudentsBundle\Entity
中找不到'ScheduleBundle\Entity\schedule'?”