Welcome Guest, Not a member yet? Register   Sign In
Cant Load Model In Controller
#1
Question 

Hi,
I'm unable to load Model in the Controller I tried to follow the tutorials but don't know where I messed up or what am I doing wrong.

RecordModel.php
PHP Code:
<?php

namespace App\Models;
use 
CodeIgniter\Model;

class 
RecordModel extends Model
{
    //protected $db;
    protected $table      'records';
    protected $primaryKey 'id';

    protected $useAutoIncrement true;

    protected $returnType    'array';
    protected $useSoftDeletes false;

    protected $allowedFields = ['name''email'];

    protected $useTimestamps true;
    protected $createdField  'created_at';

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


And this is the controller


PHP Code:
<?php

namespace App\Controllers;

use 
App\Models\RecordModel;

class 
Home extends BaseController
{
    public function index()
    {
        // return view('welcome_message');

        $records = new RecordModel();
        $data $records->findAll();
        print_r($data);
    }


this is the error i get

Code:
Error
Class 'App\Models\RecordModel' not found
APPPATH/Controllers/Home.php at line 13
Reply
#2

Where did you save your RecordModel?
Reply
#3

Did you save with character case as the class name? They have to match character case.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(10-11-2021, 07:33 PM)paulbalandan Wrote: Where did you save your RecordModel?

app/models/RecordsModel.php
InsiteFX Wrote:Did you save with character case as the class name? They have to match character case.
yes you can see above in my code
Reply
#5

File permission?
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#6

(This post was last modified: 10-12-2021, 08:21 PM by ikesela.)

RecordsModel.php : rename to RecordModel.php to match class name and namespace
Reply
#7

(This post was last modified: 10-12-2021, 11:33 PM by Kenneth Kipchumba.)

(10-12-2021, 04:52 AM)Nomie7 Wrote:
(10-11-2021, 07:33 PM)paulbalandan Wrote: Where did you save your RecordModel?

app/models/RecordsModel.php


In your controller, you are using RecordModel but your model file name is app/models/RecordsModel.php. You can choose to rename your file to RecordModel.php or use RecordsModel.php in your controller.
Reply
#8

(This post was last modified: 10-13-2021, 05:22 AM by Nomie7.)

Ok we got that solved by changing the name. I'm new so please help me understand this error now.
Here is code
PHP Code:
        $record = new RecordsModel();
        $data $record->findAll();
        print_r($data); 

Here is the error

Code:
Error
Call to a member function getResult() on bool

Im trying to follow the docs but dont how am i keep getting it wrong
Reply
#9

(10-13-2021, 05:11 AM)Nomie7 Wrote: Ok we got that solved by changing the name. I'm new so please help me understand this error now.
Here is code
PHP Code:
        $record = new RecordsModel();
        $data $record->findAll();
        print_r($data); 

Here is the error

Code:
Error
Call to a member function getResult() on bool

Im trying to follow the docs but dont how am i keep getting it wrong

Something must be wrong in your model (table name, column name, …) or in your database credentials in the configuration file because findAll() should work. Double check everything.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#10

check everything nothing is wrong checked, database name, table name, connection details and everything else. still the same. even make a new table new model file.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB