Welcome Guest, Not a member yet? Register   Sign In
Models Oddity? Fatal error: Call to a member function on a non-object
#1

[eluser]SitesByJoe[/eluser]
I have a controller that has a couple functions. The first line of each function calls a model, then runs a couple functions in the model to gather the data needed to pump into the view.

No biggie. But oddly, this started happening:

Fatal error: Call to a member function on a non-object

This error will show as soon as more than one call to the model is made on the same controller. I can't figure out why for the life of me.

My Controller Code:

Code:
class Categories extends Controller {

        function Categories()
        {
                parent::Controller();
        }
        
        function index()
        {
                // our category trees
                $this->load->model('Categories_model');
                $data['exterior_categories'] = $this->Categories_model->get_child_categories(9);
                $data['interior_categories'] = $this->Categories_model->get_child_categories(8);
                $data['home_maintenance_categories'] = $this->Categories_model->get_child_categories(12);
                
                // settings for active button
                $data['find_link_class'] = ' class="current"';
                
                // our view files to stitch together
                $data['content'] = array(
                        'main_categories'
                );
                // load it all together
                $this->load->view('template', $data);
        }
        
        function view()
        {
                // our category trees
                $this->load->model('Categories_model');
// the error shows up on the next line!
                $data['exterior_categories'] = $this->Categories_model->get_child_categories(9);
                $data['interior_categories'] = $this->Categories_model->get_child_categories(8);
                $data['home_maintenance_categories'] = $this->Categories_model->get_child_categories(12);
                
                // settings for active button
                $data['find_link_class'] = ' class="current"';
                
                // our view files to stitch together
                $data['content'] = array(
                        'main_categories'
                );
                // load it all together
                $this->load->view('template', $data);
        }        
        
}

As you can see the 2 functions, index() and view() are identical. Index() works fine if I comment out the view() function. If I un-comment the function the error comes up!

Any ideas why? Even stranger is the fact that it was working fine before.

Thanks!
#2

[eluser]SitesByJoe[/eluser]
After some more testing it appears the fact that my function is called "view" could be part of the problem...
#3

[eluser]Seppo[/eluser]
That's correct if you are running PHP 4. Take a look at Reserved names user guide page.




Theme © iAndrew 2016 - Forum software by © MyBB