Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do i get the null value in database?

Tags:

php

yii2

public function actionEvent()

{
    $event= new Events();
    $address=new Addresses();
    if($event->load(yii::$app->request->post()) && $event->save() && $address->load(yii::$app->request->post()) && $address->save())
    {

        echo $event->name;
        return $this->render('sucess',['event'=>$event]);

    }
    else{
        return $this->render('event',[
            'event'=>$event,
        'address'=>$address,
        ]);
    }
}

I don't get the record that i have posted in view form ,i get the null in database.why?

like image 961
john sunam Avatar asked Mar 12 '26 04:03

john sunam


1 Answers

I think you should indicate the name of the form element you want load inside the model

Given that the yii2 load documentation

public boolean load ( $data, $formName = null )

The form name to use to load the data into the model. If not set, formName() is used.

And in this case the form-name don't match the model

try this way

if($event->load(yii::$app->request->post('event')) && $event->save() && $address->load(yii::$app->request->post('eddress')) && $address->save())

or you should get the value from

 load($_POST['event']) 

 load($_POST['address'])  

and the assign properly for your propose.

like image 62
ScaisEdge Avatar answered Mar 13 '26 18:03

ScaisEdge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!