Symfony2 doctrine2插入记录[Semantical Error]注释

时间:2017-12-07 09:30:53

标签: php symfony doctrine-orm

当尝试将记录插入到学说时,记录正在插入但我收到错误:

  

[语义错误]注释" @Expose"在财产   从未导入C2Educate \ ToolsBundle \ Entity \ StudentScores :: $ id。   您是否忘记添加"使用"声明   注解? (500内部服务器错误)

实体:

<?php

namespace C2Educate\ToolsBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use JMS\SerializerBundle\Annotation\Type;

/**
* C2Educate\ToolsBundle\Entity\StudentScores
*
* @ORM\Table(name="tbl_student_scores")
* @ORM\Entity
*/
class StudentScores {

/**
 * @var integer $id
 *
 * @ORM\Column(name="id", type="integer", nullable=false)
 * @ORM\GeneratedValue(strategy="SEQUENCE")
 * @ORM\SequenceGenerator(sequenceName="tbl_student_scores_id_seq", allocationSize="1", initialValue="1")
 * @Expose
 * @Type("integer")
 */
protected $id;

/**
 * @var integer $studentId
 *
 * @ORM\Column(name="student_id", type="integer", nullable=true)
 * @Assert\NotBlank()
 * @Type("integer")
 */
private $studentId;


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


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

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

控制器脚本:

$em = $this->getDoctrine()->getEntityManager();
$sc = new StudentScores();
$sc->setScore((!empty($test->composite) ? $test->composite : 0));
$sc->setTestDate($test->test_date);
$sc->setcreatedBy($loggedinUser);
$sc->setCreatedAt($date);
$sc->setupdatedBy($loggedinUser);
$sc->setUpdatedAt($date);
$sc->setStudentId($returnID);
$em->persist($sc);
$em->flush();

1 个答案:

答案 0 :(得分:2)

您忘记在错误说明中添加使用语句。试试这个

use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;