CodeIgniter Forums
"Class 'App\Models\UserModel' not found" - 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: "Class 'App\Models\UserModel' not found" (/showthread.php?tid=78715)



"Class 'App\Models\UserModel' not found" - pyromanci - 03-01-2021

Ok, So this is my first venture into CI4. I have been using CI3 with a customized dynamic crud based system for all my models. I decided to try the built in models and entities.  So I created my base model in /app/Models/UserModel.php

PHP Code:
<?
namespace App\Models;

use CodeIgniter\Model;

class UserModel extends Model
{
    protected $table      = 'user';
    protected $primaryKey = 'id';
    
    protected $useAutoIncrement = true;
    protected $returnType     = 'array';
    protected $useSoftDeletes = false;

    protected $allowedFields = ['id','client_id','username','password','contact','phone','cell','email','user_admin','timeout','super_admin'];

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

    protected $validationRules    = [];
    protected $validationMessages = [];
    protected $skipValidation     = false;
    
}

?>



Then inside the auth library I'm writing. I get the error "Class 'App\Models\UserModel' not found"

PHP Code:
<?php
namespace App\Libraries;

class 
Auth {
    
    public function __construct()
    {
       if ($_SESSION['loggedIn'] == true) {
        
   $userModel = new \App\Models\UserModel();
        
   $user $userModel->find($_SESSION['login_id']);
.......
    
   }
    }
}
?>


So i'm alittle confused as to why it's not working.


RE: "Class 'App\Models\UserModel' not found" - kenjis - 03-01-2021

PHP Code:
<?
namespace App\Models; 
`<?php` ?


RE: "Class 'App\Models\UserModel' not found" - wdeda - 03-01-2021

use App\Models\UserModel; must be defined before class Auth {

PHP Code:
<?php
namespace App\Libraries;

use 
App\Models\UserModel;

class 
Auth {
    
    
public function __construct()
    {
      if ($_SESSION['loggedIn'] == true) {
           // you can use
          $userModel = new UserModel();
          $user $userModel->find($_SESSION['login_id']);
.......
      }
    }




RE: "Class 'App\Models\UserModel' not found" - pyromanci - 03-02-2021

(03-01-2021, 05:03 PM)kenjis Wrote:
PHP Code:
<?
namespace App\Models; 
`<?php` ?
I didn't even notice that. Normally I have short_open_tag turn on cause I'm stuck maintaining super old scripts. So that didn't even register to me at first. Checked the php config and it was turned off.