Yii - php warning: creating default object from empty value -


i new php yii framework don't strict. have code gets google currency exchenge rate.

for ($i = 1; $i <= 3; $i++)      {          $model = widgetcurrencyelement::model()->findbypk($i);           $buy = 100.25*$er[$i];          $buy = (int)$buy;          $buy /= 100;           $sale = $er[$i]/0.010025;          $sale = (int)$sale;          $sale /= 100;           $model->buy = $buy;          $model->sale = $sale;           if(!$model->save()){              print_r($model->geterrors());              die("not saved!");          }      }      $this->render('currency', array('er1' => $er[1], 'er2'=>$er[2], 'er3'=>$er[3])); } 

and shows me

"php warning creating default object empty value". can't understand why. reason of kind of error? '$model' not tottaly empty.

as arkoak said, 1 or more id not exist in database. it's better make sure object existence after finding it, try assign value it:

for ($i = 1; $i <= 3; $i++)  {      $model = widgetcurrencyelement::model()->findbypk($i);      if($model != null)      {          $buy = 100.25*$er[$i];          $buy = (int)$buy;          $buy /= 100;           $sale = $er[$i]/0.010025;          $sale = (int)$sale;          $sale /= 100;           $model->buy = $buy;          $model->sale = $sale;           if(!$model->save()){              print_r($model->geterrors());              die("not saved!");          }      }   } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -