【问题标题】:Symfony2 doctrine2 insert record [Semantical Error] The annotationSymfony2教义2插入记录[Semantical Error]注解
【发布时间】:2017-12-07 09:30:52
【问题描述】:

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

[语义错误] 属性中的注释“@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();

【问题讨论】:

    标签: php symfony doctrine-orm


    【解决方案1】:

    您忘记添加错误描述中所说的 use 语句。试试这个

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

    【讨论】:

    • 我在 Entity Now 中添加了这两个包 错误即将到来[Semantical Error] The annotation &amp;quot;@Assert\NotBlank&amp;quot; in property C2Educate\ToolsBundle\Entity\StudentScores::$studentId was never imported.
    • 试试use Symfony\Component\Validation\Constraints AS Assert;
    • @Developer,尝试阅读错误消息并检查是否包含此文件中使用的所有类。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-21
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多