I try to get the row where email is as in the session variable using the following code in my controller.
$usermodel = new \App\Models\UserModel();
$user=$usermodel->where('email', $session->get('email'))->find();
I do not get the proper result. Instead of getting the row containing the email in session variable, I get an empty array as result. However when i try to get all the content using findAll without filtering using email, I get the result showing all content. How can I get a filtered result with the row containing the specified email in session variable. I checked if the session variable contains value and it was found to have the correct value.
My model
<?php namespace App\Models;
use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Model;
class UserModel extends Model
{
protected $table = 'tbl_user';
protected $allowedFields = ['name','email','password','image','role_id','isActive','date_created'];
}
Please help
I tried to get the row containing the email But I get an empty array
CodePudding user response:
Can you try like this by giving the where condition in find, i have not checked the code
$usermodel = new \App\Models\UserModel();
$user = $usermodel->find(['email'=> $session->get('email')]);
CodePudding user response:
You can also use the "first()" method if the email is unique.
$user = $usermodel->where('email', session()->get('email'))->first()