Welcome Guest, Not a member yet? Register   Sign In
CI4: class not found error
#1

(This post was last modified: 04-07-2022, 01:01 AM by Ahmed Haroon.)

following video guide at Video Guide
after initial custom error handling, he is going to Insert records in database, start at around 25:50
the code i wrote during following above mentioned guide is as below:

Code:
        if (!$validation){
            return view('auth/register',['validation'=>$this->validator]);
        }else{
            // echo 'Form validated successfully!';
            $user_name=$this->request->getPost('user_name');
            $email=$this->request->getPost('email');
            $password=$this->request->getPost('password');

            $values = [
                'user_name'=>$user_name,
                'email'=>$email,
                'password'=>$password,
            ];

            // print_r($values);
            // die;

            $usersModel = new \App\Models\UsersModel();

            $query = $usersModel->insert($values);

            if(!$query){
                return redirect()->back()->with('fail', 'Oops!! Something went wrong');
                // return redirect()->to('register')->with('fail', 'Oops!! Something went wrong');
            }else{
                return redirect()->to('register')->with('success', 'Congratulations! You are registered successfully.');
            }

when run, mine is showing error (below are 2 screenshots in 1 to check error and UserModel file and class):
[Image: CI4-Error-App-Model-Users-Model-not-found.jpg]
please help, definitely i missed or overlooked something or made mistake due to my lack of knowledge.
regards

it resolved...
just for juniors like me:
the mistake was in file name UsersModel , i overlooked .php extension.
now it is inserting data.
regards
Reply
#2

Generally with namespacing etc and correct location of your models , declaring in controller something like:

Code:
use \App\Models\UsersModel;


code works so that you only have to do something along the lines of :

Code:
$handleName = new UsersModel();
CMS CI4     I use Arch Linux by the way 

Reply
#3

(04-07-2022, 01:50 AM)captain-sensible Wrote: Generally with namespacing etc and correct location of your models ,  declaring in controller something like:

Code:
use \App\Models\UsersModel;


code works so that  you only have to do something along the lines of :

Code:
$handleName = new UsersModel();
thanks @captain-sensible for great help to understand it, i am newly entered in this CI world! 
regards.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB