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);
Utility::getJsonResponse($result);
}
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;
$lo_dynamicFormField->save();
}
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')){
if($i==0){
$ls_sqlToUpdate .= "`".$key."` = '" .$value."'";
$i++;
}else{
$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…