1
我一直在按照一些教程來獲取Doctrine的運行,並且當我嘗試將一個對象插入數據庫時似乎掛斷了。作爲參考,這是我在下面:doctrine 2 tutorial在Doctrine 2/CodeIgniter中找不到實體模型2
- 學說是安裝在應用程序/庫文件夾
- Doctrine.php引導程序將在應用程序/庫文件夾
- 一個cli.php文件被創建在應用程序/文件夾
- 本教程沒有說把我的第一個實體模型,所以我把它放在應用程序/模型
命名實體;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
* @Table(name="user")
*/
class User
{
/**
* @Id
* @Column(type="integer", nullable=false)
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @Column(type="string", length=32, unique=true, nullable=false)
*/
protected $username;
/**
* @Column(type="string", length=64, nullable=false)
*/
protected $password;
/**
* @Column(type="string", length=255, unique=true, nullable=false)
*/
protected $email;
/**
* The @JoinColumn is not necessary in this example. When you do not specify
* a @JoinColumn annotation, Doctrine will intelligently determine the join
* column based on the entity class name and primary key.
*
* @ManyToOne(targetEntity="Group")
* @JoinColumn(name="group_id", referencedColumnName="id")
*/
protected $group;
}
/**
* @Entity
* @Table(name="group")
*/
class Group
{
/**
* @Id
* @Column(type="integer", nullable=false)
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @Column(type="string", length=32, unique=true, nullable=false)
*/
protected $name;
/**
* @OneToMany(targetEntity="User", mappedBy="group")
*/
protected $users;
}
- 創造了我在DB模式沒有問題:PHP cli.php ORM:架構工具:創建
- 拿到「使用原則」下的最後一步設定
嘗試使用在我的控制器下面的代碼,並得到了一個錯誤
$em = $this->doctrine->em; $user = new models\User; $user->setUsername('Joseph'); $user->setPassword('secretPassw0rd'); $user->setEmail('josephatwildlyinaccuratedotcom'); $em->persist($user); $em->flush();
主要生產
Fatal error: Class 'models\User' not found in C:\wamp\www\ci\application\controllers\Home.php on line 11
我唯一的想法是,可能有路徑的東西,因爲我在窗口或我把我的實體模型放在錯誤的地方。
嗯,奇怪,不知道爲什麼他會在教程中將其列爲模型\用戶。謝謝。 –
啊,我沒有注意到。這可能是一個錯誤 - 但我很驚訝,評論中沒有任何關於它的內容(我剛剛離開了一個)。 –