Welcome Guest, Not a member yet? Register   Sign In
"Class 'App\Models\UserModel' not found"
#1

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.
Reply
#2

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

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']);
.......
      }
    }

Reply
#4

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB