$model->save is not waorking when $model->findOne(DynamicValue)

Hi all,

I’m getting error when I trying to save a model after loading that using a dynamic primary key. Let me describe in details…

I am working in Angular 2 and after service call, rest is handle by the Yii2.

So I send an array of data and try to update a field …

First my Service hits here…

public function actionAddOrUpdateFormFieldProperty(){

        $post = file_get_contents("php://input");

        $post = json_decode($post);

        $lo_obj = new \common\models\MstDynamicFormField();

        $result = $lo_obj->addOrUpdateFormFieldProperty($post);



Here $post containing a full row of a db-table…

Now ""addOrUpdateFormFieldProperty"" I did

public function addOrUpdateFormFieldProperty($formField) {

 $formField = (array)$formField;

 $lo_dynamicFormField = $this->findModel($formField['dynamic_form_field_id']);

 $lo_dynamicFormField->attributes = $formField;





Now the issue is "save()" is not working.

Even if I write custom Function like…

        $formField = (array)$formField;

        $lo_dynamicFormField = $this->findModel($formField['dynamic_form_field_id']);

        $ls_sqlToUpdate = "UPDATE {{%mst_dynamic_form_field}} SET ";

        foreach($la_dynamicFormField as $key=>$value){

            if(($key != 'dynamic_form_field_id') && ($key != 'template')){


                    $ls_sqlToUpdate .= "`".$key."` = '" .$value."'";



                    $ls_sqlToUpdate .= ", `".$key."` = '" .$value."' ";





        $ls_sqlToUpdate .= "WHERE `dynamic_form_field_id` = ".$formField['dynamic_form_field_id'];

        $la_commandToUpdate = Yii::$app->db->createCommand($ls_sqlToUpdate)->execute();

Still its not working …Even not showing any error in browser ‘Console or Network’…Only returns Error code 500…

Please Help me out…


Your way of debugging is not right. You have to use print and die in each method. Each method try to print output and end of the method put die , like die(‘method ends’). In this way you will confirm each method is working fine or not.


Chandran Nepolean