Exemplo n.º 1
0
 public function actionSave()
 {
     if (!empty($_POST['course'][Course::PK])) {
         $item = Course::findByPK($_POST['course'][Course::PK]);
     } else {
         $item = new Course();
     }
     $item->fill($_POST['course']);
     $item->save();
     if ($item->wasNew() && !empty($_POST['lessonsCount'])) {
         $lessonsCount = (int) $_POST['lessonsCount'];
         for ($i = 1; $i <= $lessonsCount; $i++) {
             $lesson = new Lesson();
             $lesson->num = $i;
             $lesson->title = 'Урок ' . $i;
             $lesson->course = $item;
             $lesson->save();
         }
     }
     $this->redirect('/admin/courses');
 }