我的应用程序中有项目和任务,我希望(作为一个简单的例子)在创建项目后,默认情况下会生成两个任务并分配给该项目。
所有项目的任务开始都是一样的。然后就可以更新单个项目的任务......
例如:
我创建了Project_A - >生成task1,task2
我创建Project_B - >生成task1,task2
Yii有可能吗?
答案 0 :(得分:0)
将此功能放在 Project.php 模型文件中:
public function beforeSave() {
// Create two tasks and save them to get an auto-increment key from the database
$task1 = new Task;
$task1->save();
$task2 = new Task;
$task2->save();
// $this refers to the current project
// Assuming we have two fields to store the IDs of the tasks
$this->task1 = $task1->primaryKey;
$this->task2 = $task2->primaryKey;
return parent::beforeSave();
}