无论我将模型值设置为什么,Doctrine都只插入空值

时间:2014-03-06 03:54:02

标签: php doctrine-orm

以下是我创建锦标赛并保存的方法:

  $tournament =  new Entities\Tournament();
  $tournament->setTitle("this is strange");
  var_dump($tournament->getTitle());
  $this->em->persist($tournament);
  $this->em->flush();

这是锦标赛课程:

<?php
namespace Entities;/** * @Entity @Table(name="jos_gsa_tournament") */
use \Doctrine\Common\Collections\ArrayCollection;
class Tournament { /** @Id @Column(type="integer") @GeneratedValue */
  protected $id;//** @Id @Column(type="integer") */
  protected $title;//** @Column(type="string",length=255) */

  public function getId() {
    return $this->id;
  }
  public function setId($id) {
    $this->id = $id;
  }
  public function getTitle() {
    return $this->title;
  }
  public function setTitle($title) {
    $this->title = $title;
  }
}
?>

运行上面提到的代码后,我在数据库中有一个锦标赛条目,标题为空字符串。即使var_dump转储&#34;这很奇怪&#34;。

2 个答案:

答案 0 :(得分:1)

您的注释语法看起来不正确。看起来应该是这样......

namespace Entities;

use Doctrine\Common\Collections\ArrayCollection;

/**
 * @Entity
 * @Table(name="jos_gsa_tournament")
 */
class Tournament {
    /** @Id @Column(type="integer") @GeneratedValue */
    protected $id;
    /** @Column(type="string",length=255) */
    protected $title;

答案 1 :(得分:0)

搞砸了我的注释,应该是:

<?php
namespace Entities;
use \Doctrine\Common\Collections\ArrayCollection;
/** * @Entity @Table(name="jos_gsa_tournament") */
class Tournament { 
  /** @Id @Column(type="integer") @GeneratedValue */
  protected $id;
  /** @Column(type="string",length=255) */
  protected $title;