[英]PHP Fatal error: Call to undefined method stdClass::save() - Yii framework
我使用Yii Framework,在我的代碼中,我有:
$model=partidascapturainfo::model()->findByAttributes(array('capturainfoid'=>$idCaptura,'metricaid'=>$metricaId,'proyectoproductoid'=>$productoId));
if ($model!==null){
if($model->save()){
$response->status = "1";
$response->message= "La Informacion se subio correctamente con el Id ".$idCaptura;
$this->logInFile("model->save() ok");
}else{
$response->status = "0";
$response->message= "La Informacion no fue enviada intentelo mas tarde";
$this->logInFile("model->save() not posible-model:".print_r($model->getErrors()));
}
}else{
$this->logInFile("model is null");
$this->logInFile(print_r($model->getErrors()));
}
我是一個Java程序員,所以,我對PHP不太熟悉,但是,我可以看到$ model不是null。 但是,我找不到一種顯示$ model內容的方法:
print_r($model); // display 1
get_object_vars($model); // display Array
var_dump($model); // display nothing
很有必要說一下,我將請求從Android中的PhoneGap應用發送到了php腳本。 我拍攝並上傳照片,然后發送請求。 因此,例如,我無法在firebug中進行調試。
我發現的唯一方法是用數據寫入日志文件($ this-> logInFile())
我不知道該如何解決...在其他主題中,他們說發生異常是因為$ model為null,但我的不是。
同樣,能夠記錄由執行的sql查詢將對您有很大的幫助:
model()->findByAttributes(array('capturainfoid'=>$idCaptura,'metricaid'=>$metricaId,'proyectoproductoid'=>$productoId));
登錄文件功能:
function logInFile($msg){
$path = "/logs/logfile.log";
$f = @fopen(getcwd().$path, 'a+');
//$req = json_encode($_REQUEST);
//@fputs($f, date("Y/m/d g:i:s").$req."\n");
@fputs($f, $msg."\n");
@fclose($f);
}
任何幫助,將不勝感激!
您將明確檢查是否為null(!== null),因此如果模型是空對象,則此檢查將不會捕獲該對象。
供調試使用
print_r($model, true)
要么
var_export($model, true)
您正在使用的當前調用會將信息刷新到默認輸出,並且對控制台調用很有用。 將返回參數設置為true,將打印出信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.