controllers/QuestionBankController.php
/**
     * Creates a new QuestionBank model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new QuestionBank model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new QuestionBank model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new QuestionBank();
        $category = ArrayHelper::map(Category::find()->all(), 'category_id', 'category_name');
        $questionType = ArrayHelper::map(QuestionType::find()->all(), 'question_type_id', 'question_type');
        $level = ArrayHelper::map(Level::find()->all(), 'level_id', 'level_name');
        $this->view->params['category'] = $category;
        $this->view->params['questionType'] = $questionType;
        $this->view->params['level'] = $level;
        $model->max_mark = 1;
        $model->time_alloted = 60;
        if(!empty($_POST)){
            $model->attributes=$_POST['QuestionBank'];
            $valid=$model->validate();
            if ($valid && $model->save()) {
                if ($model->question_type_id ==  1) { 
                    return $this->redirect(['option', 'id' => $model->question_bank_id]);
                }
                if ($model->question_type_id ==  2) { 
                    return $this->redirect(['multi-option', 'id' => $model->question_bank_id]);
                }
                if ($model->question_type_id ==  3) { 
                    return $this->redirect(['match-column', 'id' => $model->question_bank_id]);
                }
                if ($model->question_type_id ==  4) { 
                    return $this->redirect(['upload-image', 'id' => $model->question_bank_id]);
                }
                if ($model->question_type_id ==  5) { 
                    return $this->redirect(['essay', 'id' => $model->question_bank_id]);
                }
            }
            return $this->redirect(['view', 'id' => $model->question_bank_id]);
        } else {
            return $this->render('create', [
                'model' => $model,
                'category'=>$category,
                'questionType'=>$questionType,
                'level'=>$level,
            ]);
        }
    }
public function actionCreate ( ) { $ model = new QuestionBank ( ) ; $ category = ArrayHelper :: map ( Category :: find ( ) -> all ( ) , 'category_id' , 'category_name' ) ; $ questionType = ArrayHelper :: map ( QuestionType :: find ( ) -> all ( ) , 'question_type_id' , 'question_type' ) ; $ level = ArrayHelper :: map ( Level :: find ( ) -> all ( ) , 'level_id' , 'level_name' ) ; $ this -> view -> params [ 'category' ] = $ category ; $ this -> view -> params [ 'questionType' ] = $ questionType ; $ this -> view -> params [ 'level' ] = $ level ; $ model -> max_mark = 1 ; $ model -> time_alloted = 60 ; if ( ! empty ( $ _POST ) ) { $ model -> attributes = $ _POST [ 'QuestionBank' ] ; $ valid = $ model -> validate ( ) ; if ( $ valid && $ model -> save ( ) ) { if ( $ model -> question_type_id == 1 ) { return $ this -> redirect ( [ 'option' , 'id' => $ model -> question_bank_id ] ) ; } if ( $ model -> question_type_id == 2 ) { return $ this -> redirect ( [ 'multi-option' , 'id' => $ model -> question_bank_id ] ) ; } if ( $ model -> question_type_id == 3 ) { return $ this -> redirect ( [ 'match-column' , 'id' => $ model -> question_bank_id ] ) ; } if ( $ model -> question_type_id == 4 ) { return $ this -> redirect ( [ 'upload-image' , 'id' => $ model -> question_bank_id ] ) ; } if ( $ model -> question_type_id == 5 ) { return $ this -> redirect ( [ 'essay' , 'id' => $ model -> question_bank_id ] ) ; } } return $ this -> redirect ( [ 'view' , 'id' => $ model -> question_bank_id ] ) ; } else { return $ this -> render ( 'create' , [ 'model' => $ model , 'category' => $ category , 'questionType' => $ questionType , 'level' => $ level , ] ) ; } }
Creates a new QuestionBank model.
Creates a new QuestionBank model .
// Get all values for drop down box /*
        $nosOption = [
                2 => 2,
                3 => 3,
                4 => 4,
                5 => 5,
                ]; // Option value restricted to divisible values
        */ //$this->view->params['nosOption'] = $nosOption; // It is of the type Multiple Question Single ansswer // It is of the type Multiple Question Multiple ansswers // It is of the type Match the columns // It is of the type Match the columns // It is of the type Essay //'nosOption'=>$nosOption,