【发布时间】:2011-09-02 09:44:19
【问题描述】:
我正在开发 Symfony 应用程序中的某种通知模块。我正在迭代Doctrine_Collection 的用户,为每个在其个人资料中具有活动标志的用户创建一个Notification:
// Create and define common values of notification
$notification = new Notification();
$notification->setField1('...');
$notification->setField2('...');
...
// Post notification to users
foreach ( sfGuardUserTable::getInstance()->findByNotifyNewOrder(true) as $user ) {
$notification->setUserId($user->getId());
$notification->save();
}
问题是,一旦我保存了第一个通知,我就无法重用该对象在数据库中存储新记录。我试过$notification->setId() 和null 和'',但是保存会更新对象而不是保存新对象。
有没有办法重用$notification 对象?我想这样做是因为通知字段创建的逻辑有点复杂。
【问题讨论】:
标签: symfony1 save reusability doctrine-collection