请在此处查看代码:http: //pastie.org/1092106
当我在 Blog 上调用 createPost 方法时,我不断收到异常,内容如下:
At line 474 in lib/Doctrine/ORM/Persisters/BasicEntityPersister.php - Undefined index: id
哦,还有......我在每个页面加载时重新生成 $_SESSION['User'] ,因此该对象不会与实体管理器或类似的东西分离。
以下是 Doctrine2 所设想的模式:
Array (
[0] => CREATE TABLE Note (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, text LONGTEXT NOT NULL, created DATETIME NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB
[1] => CREATE TABLE BlogPost (note_id INT NOT NULL, blog_name VARCHAR(255) NOT NULL, PRIMARY KEY(note_id, blog_name)) ENGINE = InnoDB
[2] => CREATE TABLE User (email VARCHAR(95) NOT NULL, id INT NOT NULL, password VARCHAR(32) NOT NULL, alias VARCHAR(15) DEFAULT NULL, firstName VARCHAR(20) DEFAULT NULL, lastName VARCHAR(20) DEFAULT NULL, enabled TINYINT(1) NOT NULL, created DATETIME NOT NULL, UNIQUE INDEX User_id_uniq (id), PRIMARY KEY(email)) ENGINE = InnoDB
[3] => ALTER TABLE Note ADD FOREIGN KEY (user_id) REFERENCES User(id)
[4] => ALTER TABLE BlogPost ADD FOREIGN KEY (note_id) REFERENCES Note(id)
[5] => ALTER TABLE BlogPost ADD FOREIGN KEY (blog_name) REFERENCES Blog(name)
)
希望有人可以提供帮助!