Welcome Guest, Not a member yet? Register   Sign In
Problem accessing method in model
#1

[eluser]jloosli[/eluser]
I'm sure this is something simple that I'm overlooking, but after hours of troubleshooting and web searches, I can't figure this out.

I have a model called Units that looks like this:
Code:
class Units extends Model {
    function __construct() {
        parent::__construct();
    }
    
    function getActive() {
        $this->db->where('u_active','y');
        $this->db->order_by('u_name','asc');
        $result=$this->db->get('units')->result();
        return $result;
    }
}
I've used $this->units->getActive() successfully in other views, but I created a new view this morning and have the following code in it:
Code:
$this->load->model('units');
$units=$this->units->getActive(); //This is line 12

I get the following CI error: Undefined property: CI_Loader::$units
as well as the PHP Error:
Fatal error: Call to a member function getActive() on a non-object in C:\xampp\htdocs\ci\system\application\views\invoice.php on line 12

I'm pretty sure that the model is loading, because I commented out line 12, enabled the profiler, and saw the memory usage change when I commented out the line to load the model.

So...I'm stumped. Any idea why I can't see this method in this view?
#2

[eluser]Neeraj Kumar[/eluser]
I think you are trying to load models in your view, which is a bad bad idea.

Try loading model in controller and pass only the data from model to view.
#3

[eluser]jloosli[/eluser]
<slap head>Wow. I feel dumb. Loaded in controller and worked like a charm. </slap head>

Thanks a lot. I figured it was bad form, but I didn't realize that it doesn't work to load a model in a view.




Theme © iAndrew 2016 - Forum software by © MyBB