Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error: CodeIgniter\Database\BaseResult::getResult in CodeIgniter

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:

enter image description here

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

like image 249
Mauro Dias Avatar asked Nov 30 '25 08:11

Mauro Dias


1 Answers

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();

like image 198
Heli Sangueve Avatar answered Dec 01 '25 22:12

Heli Sangueve