Welcome Guest, Not a member yet? Register   Sign In
CI3 - Cannot access a function from the model
#1

Hey team, am I missing something fundamental in my CI config?
I can load a model (it seems to be loaded when I print_r $this) but cannot access a function from inside it.

The model is named Projects.php and is in the "models" folder.

Projects.php only contains this:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Projects extends CI_Model {

    public function get_last_ten_entries()
        {
            $testString = "Inside the model";
        return $testString;
        }
    
}

And lines 10 and 11 in the view I'm using are:
Code:
        $this->load->model('Projects');
    $this->projects->get_last_ten_entries();

The rest of the file works fine, does everything it should.

And this is the error that comes up:
Code:
A PHP Error was encountered
Severity: Notice

Message: Undefined property: CI_Loader::$projects

Filename: views/body.php

Line Number: 11

Why is it undefined if the model is already loaded?
Do I need to do something else to use a model in a view?
Reply


Messages In This Thread
CI3 - Cannot access a function from the model - by timps - 05-03-2020, 05:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB