dates and array data

I have two tables:

1.course

  1. lectures

I want the values in lectures to be automatically generated based on the input of course, when save button is click in course.

For exam, if course_format is weekly and course_format_no is 3, the start_date will be selected. If start_date is 24th November, 2016. then lecture_name will be something like this:

18 November - 24 November,

25 November - 1 December,

2 December - 8 December.

And lecture_code will be something like this:

1,

2,

3

Note that lecture_name is increased by one week.

lecture_name and lecture_code are columns in lectures table.

It should be saved in different fields and not as a big string.

Also I want it done in actionCreate in my CourseController

[b]

course model

[/b]




    public function attributeLabels()

    {

        return [

            'course_id' => 'Course ID',

            'course_category_id' => 'Course Category ID',

            'course_code' => 'Course Code',

            'course_name' => 'Course Name',

            'course_num' => 'Course Num',

            'course_summary' => 'Course Summary',

            'course_start_date' => 'Course Start Date',

            'course_format' => 'Course Format',

            'course_format_no' => 'Course Format No',

        ];

    }



[b]

lectures model

[/b]




    public function attributeLabels()

    {

        return [

            'lecture_id' => 'Lecture ID',

            'course_id' => 'Course ID',

            'lecture_code' => 'Lecture Code',

            'lecture_name' => 'Lecture Name',

        ];

    }



I started with something like this, but dont know what to do again




public function actionCreate()

{

    $model = new Course();


    if ($model->load(Yii::$app->request->post()) && $model->save()) {

        //The course was created successfully, so we can use its data to make lectures


        //loop through and make the lecture with topic#

        for( $i = 1; $i <= $model->course_format_no; $i++ ) {

            $lecture = new Lectures();

             // please what do I do here


            // fill in other lecture data here


            $lecture->save();

            // if you needed to make a course_lecture relation, then change $lecture->save(); 

            // into an if statement and make the relationship somewhere down here.

        }


    }

}