CodeIgniter loading models error when changing web host
Posted November 9th, 2008 in PHP
I've been in the process of moving a website that uses the CodeIgniter PHP framework from one of my servers to another provider's server and kept getting "Fatal error: Call to a member function on a non-object" type errors when trying to use some of my models. This post looks at what was causing the issue.
The code was doing this:
$this->load->model('category_model');
$category = $this->category_model->get_category_by_url($category_url);
and I was getting the following error:
Fatal error: Call to a member function on a non-object in /path/to/controllers/mycontroller.php on line 65
I tried changing the case to Category_Model, Category_model etc in both the controller and the model and kept getting the same error. The weird thing was some of the other functions in the website worked just fine using the same sort of controller/model calls.
After wasting 30 or 40 minutes trying to diagnose the issue I thought I should check to see which version of PHP was running on this particular server and was surprised to find it was PHP 4.4, and not 5.2 which is what I was expecting. Although all new hosting accounts are supposed to default to PHP 5.2 with this provider for some reason this account didn't.
A quick change and the site is now running through PHP 5.2. The errors have stopped and now the site works... So although this may not solve your issue, it's worth having a check and see if it's a PHP version issue.

Comments
blog comments powered by Disqus