Unable to save data in database

Hello experts,

Can you please guide me how to save data in the database? below is the model, controller and view code for your reference.

Model:





class TestForm extends Model


 public static function tableName()

    {

        return '{{%test%}}';

    }

{

     

     public $value1;

     public $value2;

     public $value3;

     

 public function rules()


	{

	return[

        

        ['value1','required'], 

        ['value2','required'],

              ];

	}

 

  public function attributeLabels()

    {

        return [

            

            'value1' => '',

            'value2' => '',

            'value3' => 'Test output',

            

               ];

    }






Controller:







class TestController extends Controller


{

  

  public function actionTest(){

      

    $val1='A';

    $val2='B';

    $val3='C';


    return $this->render('index', ['Text1' => $val1, 'Text2' => $val2, 'Text3'=>$val3]);

    } 

}




View:




<div id= "content">

         <?php $form = ActiveForm::begin([

           'id' => 'form-testform'])?>

                    

<div class="row">

	<div class="col-xs-1">


	<?=$Text1 ?>


	</div>


	<div class="col-xs-1">


	<?=$Text2 ?>


	</div>

        <div class="col-xs-1">


	<?=$Text3 ?>


	</div>

			

	</div>

<div class="form-group"><?php ActiveForm::end(); ?> </div>




Thanks in advance.

Regards,

Sid

Try render code with Gii. This will be a good hint.

Hello Experts,

Is there any way to relate "$value1, $value2, $value3" of Model with "$val1, $val2, $val3" of controller, so that when trigger submit button, the values will be saved in the db?

Regards,

Sid

You have to learn the basic concepts of the yii framework.

Read the following sections of the guide before you ask another question.

Getting Started

  • Running Applications

  • Saying Hello

  • Working with Forms

  • Working with Databases

I agree with softark. You need to read the guide to get used to Yii. Model can use acrive record or data access objects

Hello team,

Thanks for your inputs.

I have understood the points. I have sorted out the issue.

Regards,

Sid