controllers/QuestionBankController.php
/*
    * Function for Multiple Question Single Ansswer
    */
Function for Multiple Question Single Ansswer
Function for Multiple Question Single Ansswer
public function actionOption( $id){
        $optionModel = new Option(); 
        $model = $this->findModel($id);
        if(!empty($_POST)){
            $correct = $_POST['correct']; 
            for( $i = 1; $i <= $model->nos_option; $i++ ) {
                $optionModel->option_id = NULL; 
                $optionModel->isNewRecord = true;
                $optionModel->score = 0; 
                if ($i == $correct) {
                    $optionModel->score = $model->max_mark;
                } 
                $optionModel->question_bank_id = $id;
                $optionModel->question_option = $_POST['option_' . $i ];
                $optionModel->save();
            }
            return $this->redirect(['index']); 
        } else { 
            return $this->render('option', [
                'model' => $model,
           ]);
        }
    }
public function actionOption ( $ id ) { $ optionModel = new Option ( ) ; $ model = $ this -> findModel ( $ id ) ; if ( ! empty ( $ _POST ) ) { $ correct = $ _POST [ 'correct' ] ; for ( $ i = 1 ; $ i <= $ model -> nos_option ; $ i ++ ) { $ optionModel -> option_id = NULL ; $ optionModel -> isNewRecord = true ; $ optionModel -> score = 0 ; if ( $ i == $ correct ) { $ optionModel -> score = $ model -> max_mark ; } $ optionModel -> question_bank_id = $ id ; $ optionModel -> question_option = $ _POST [ 'option_' . $ i ] ; $ optionModel -> save ( ) ; } return $ this -> redirect ( [ 'index' ] ) ; } else { return $ this -> render ( 'option' , [ 'model' => $ model , ] ) ; } }
Function for Multiple Question Single Ansswer
Function for Multiple Question Single Ansswer
// get the option model // Sl.no of the correct answer //reset the model, needed for saving in loop //primary key(auto increment id) id //reset the score // One mark for correct answer // correct answer to be set for full marks //save the model // Go to theindex view of question bank // Go to option form