CodeIgniter Forums
Call to a member function getFirstRow() on bool - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Call to a member function getFirstRow() on bool (/showthread.php?tid=79612)



Call to a member function getFirstRow() on bool - lucavalentino - 07-07-2021

I am converting from codeigniter 3 to 4. I would like to use the find function, but I get Call to a member function getFirstRow () on bool

Model

PHP Code:
namespace App\Models;

use 
CodeIgniter\Model;
use 
App\Entities\Studente_e;

class 
Studente_m extends Model
{
protected 
$table      'tblstudenti';
protected 
$primaryKey 'NUM_MATRIC';
protected 
$useAutoIncrement true;
protected 
$returnType 'App\Entities\Studente_e'// configure entity to studebnte
protected $useSoftDeletes true;

protected 
$allowedFields = ['name''email'];

/*protected $useTimestamps = false;
protected $createdField  = 'created_at';
protected $updatedField  = 'updated_at';
protected $deletedField  = 'deleted_at';*/

protected $validationRules    = [];
protected 
$validationMessages = [];
protected 
$skipValidation    false;
protected 
$useTimestamps true;
function 
verifica_stud($id$email){
return 
$result $stud_m->find($id$email);
}} 


Controller

PHP Code:
namespace App\Controllers;
use 
CodeIgniter\Controller;
use 
App\Models\login_m;
use 
App\Models\studente_m;
use 
App\Models\professore_m;

use 
App\Libraries\MY_Form_validation;

class 
Registra extends BaseController
{
public function 
__construct()
{...
$this->studente_m= new studente_m();
...}
public function 
index()
{...
$query $this->studente_m->verifica_stud($id$email);
...} 



RE: Call to a member function getFirstRow() on bool - ikesela - 07-07-2021

should be like this only (no $email), search by primarykey
return $result = $stud_m->find($id);


RE: Call to a member function getFirstRow() on bool - InsiteFX - 07-08-2021

Using QueryBuilder you can do it like this.

PHP Code:
$data = [];

$builder $this->builder();

$query $builder->where('id'$id)
                ->where('email'$email)
                ->get();

if (isset(
$query))
{
    $data $query->getRowArray();
}

$query->freeResult();

return 
$data

Give that a try.


RE: Call to a member function getFirstRow() on bool - rdconsolo - 09-21-2024

It can be a lot of things.
Read the log on writable/logs.
In my case was a foreign-key left on the database table pointing to a non existing field.
Good luck.