'automatically change data returns from the model in CodeIgniter 4
I want to change automatically the data returns from the model in CodeIgniter 4. That's what comes to my mind, but it's not works:
class UserModel extends Model {
protected $afterFind = ['getImage'];
protected function getImage(array $data) {
if ($data['user_image'] == 0) {
$data['user_image'] = "New Value";
}
return $data;
}
}
Anyone have an idea how to do that? Thanks.
Solution 1:[1]
Solution:
class UserModel extends Model {
protected $afterFind = ['getImage'];
protected function getImage(array $data) {
if ($data['data']['user_image'] == 0) {
$data['data']['user_image'] = "New Value";
}
return $data;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | roev |
