I'm getting an " array to string conversion " error in codeigniter ` there is the function
==> Modele
public function getCodeActivationWebsite($EmailCode) {
$this->db->select('advancedActivationWebsiteCode')->from($this->table)->where('advancedActivationEmailCode' , $EmailCode);
$query = $this->db->get();
return $query->result();
}
==> controllers
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;
}
}
When you call your model function getCodeActivationWebsite
the data is returned as an object. Assuming your works query properly this object will contain the string that you want to access.
In your code the object is stored in the $name
variable, so when you do this: file_get_contents(PATH_UPLOADS_ACTIVATION_WEBSITE . $name);
you get an error.
Instead you have to identify the string in your object. For example it might be $name[0]->name
. The best way to identify where the string is located is to print_r
your object and locate the data.
Read more about how to access data from an object here: PHP access data of an object or PHP: Getting data out of an object