Welcome Guest, Not a member yet? Register   Sign In
Model error with builder first()
#1

Hi,

I'm trying to do a simple model query but it doesn't seem to work as defined in the official documentation.

Here's my code below:
PHP Code:
<?php 
namespace App\Models;  

use CodeIgniter\Model;

class 
UtilisateurModel extends Model {

    protected $db;

    protected $table           'utilisateur';
    protected $primaryKey      'id_utilisateur';
    protected $useAutoIncrement true;
    protected $returnType      'array';
    
    
protected $allowedFields = [
        'nom',
        'email',
    ];

    public function __construct() {
        $this->db db_connect();
    }

    public function get_from_email ($email) {
        return $this->where('email'$email)->first();
    }

When I call (new UtilisateurModel)->get_from_email($email);

I got the error:
Argument 1 passed to CodeIgniter\Database\BaseResult::getFirstRow() must be of the type string, null given

How can I solve that?
Regards
Reply
#2

Remove your constructor.
Reply
#3

Yes that does the charm!

It was there when I took the code and I didn't challenged it.

Cheers
Reply
#4

(12-21-2022, 10:47 PM)kenjis Wrote: Remove your constructor.

thank you for this! i was not conscious to see that i too was having the same problem because i was overriding the parent constructor !
Reply




Theme © iAndrew 2016 - Forum software by © MyBB