[英]Array to string conversion In Codeigniter
我在codeigniter中遇到“數組到字符串轉換”錯誤,有該功能
==>模型
public function getCodeActivationWebsite($EmailCode) {
$this->db->select('advancedActivationWebsiteCode')->from($this->table)->where('advancedActivationEmailCode' , $EmailCode);
$query = $this->db->get();
return $query->result();
}
==>控制器
function downloadfile($codeActivation = '') {
// Read the file's contents
$name = $this->advanced->getCodeActivationWebsite($codeActivation).'.html';
$data = file_get_contents(PATH_UPLOADS_ACTIVATION_WEBSITE . $name); // La path n'est pas valide
//getCode
//ActivationWebsite($EmailCode)
if (force_download($name, $data)) {
return true;
} else {
return false;
}
}
調用模型函數getCodeActivationWebsite
,數據作為對象返回。 假設您的作品查詢正確,則此對象將包含您要訪問的字符串。
在您的代碼中,對象存儲在$name
變量中,因此執行此操作時: file_get_contents(PATH_UPLOADS_ACTIVATION_WEBSITE . $name);
你得到一個錯誤。
相反,您必須在對象中標識字符串。 例如,它可能是$name[0]->name
。 識別字符串所在位置的最佳方法是將對象print_r
並定位數據。
在此處閱讀有關如何從對象訪問數據的更多信息: PHP訪問對象的數據或PHP:從對象中獲取數據
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.