I am trying to use CodeIgniter 4 crud function findAll and I am getting the error Argument 1 passed to CodeIgniter\Database\BaseResult::getResult() as shown below:

Here is my model
<?php
namespace App\Models\Admin\User_management;
use CodeIgniter\Model;
class UsuariosModel extends Model
{
protected $table = 'users';
protected $primaryKey = 'user_id';
protected $returnType = 'array';
protected $allowedFields = ['user_login', 'user_psw', 'user_full_name', 'user_email', 'user_telef', 'user_image', 'user_date_of_birth', 'user_gender', "user_created_at", "user_updated_at", "user_deleted_at"];
protected $useTimestamps = true;
protected $useSoftDeletes = true;
protected $createdField = 'user_created_at';
protected $updatedField = 'user_updated_at';
protected $deletedField = 'user_deleted_at';
and this is my controller
public function delete_users(){
//$this->validateViewUserData();
//$user_id = $this->request->getVar('user_id', FILTER_SANITIZE_STRING);
//$this->deleteUsers($user_id);
$user_model = new UsuariosModel();
$users = $user_model->findAll();
}
DROP TABLE IF EXISTS `users`;
CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`user_login` varchar(40) NOT NULL,
`user_psw` varchar(255) NOT NULL,
`user_full_name` varchar(100) NOT NULL,
`user_email` varchar(80) NOT NULL,
`user_telef` int(16) NOT NULL,
`user_image` varchar(255) DEFAULT NULL,
`user_created_at` datetime NOT NULL,
`user_updated_at` datetime DEFAULT NULL,
`user_deleted_at` datetime DEFAULT NULL,
`user_date_of_birth` date NOT NULL,
`user_gender` int(1) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=119 DEFAULT CHARSET=utf8;
Other crude functions like update, save, delete are working well, only when i use find() or findAll() dont work in controller and in model itself
i've had the same problem. To solve it, you need to call the base class constructor in the model constructor tha you're using: parent:__construct();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With