Ahmad Almosallam
Ahmad Almosallam

Reputation: 304

Getting error Class 'Codeigniter\Model' not found in codeigniter 4

I'm facing this error and it`s weird I check everywhere and I think the code is good. the problem is I want an instance from my model in controller but it gives the error above error image I 'll put the code below. this is controller

<?php namespace App\Controllers\User;

use App\Controllers\BaseController;

use App\Models\UserModel;

class Users extends BaseController{

    public function index(){
        echo view('includes/header');
        echo view('user/index');
        echo view('includes/footer');
    }

    public function login(){

    }
    public function register(){

        $model = new UserModel();

        if($this->request->getPost()){
            return "f";
        }
        
        echo view('includes/header');
        echo view('user/register');
        echo view('includes/footer');
    }

}

this is model

<?php

namespace App\Models;

use Codeigniter\Model;

class UserModel extends Model
{

    protected $table      = 'users';
    protected $primaryKey = 'id';

    protected $returnType     = 'array';
    protected $useSoftDeletes = true;

    protected $allowedFields = ['email', 'username', 'password'];

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

    protected $validationRules    = [
        'email' => 'required|valid_email',
        'username' => 'required|min_length[2]|max_length[10]',
        'password' => 'required|min_length[8]|max_length[20]'
    ];
    protected $validationMessages = [
        'email' => [
            'required' => 'This field is required',
            'valid_email' => 'email is not valid make sure you wrote it right'
        ],
        'username' => [
            'required' => 'This field is required',
            'min_length' => 'the min username is 2',
            'max_length' => 'the max username is 10'
        ],
        'password' => [
            'required' => 'This field is required',
            'min_length' => 'the min pasword is 8',
            'max_length' => 'the max pasword is 20'
        ]
    ];
    // protected $skipValidation     = false;

}

please help I'm stuck in there :(

..............................

Upvotes: 0

Views: 5251

Answers (1)

Deepraj Chouhan
Deepraj Chouhan

Reputation: 21

the file name you used is:

use Codeigniter/Model

replace it with :

use CodeIgniter/Model

Upvotes: 2

Related Questions