I uploaded a CakePHP application on the production. It is working on my and my friend’s localhost. On the production I got the following error when trying to access different controllers:
Error: Call to a member function find() on a non-object
File: /app/Controller/GroupsController.php
Line: 10
<?php
class GroupsController extends AppController {
var $name = 'Groups';
var $displayField = 'name';
var $helpers = array('Paginator', 'Html', 'Form');
function index() {
$groups = $this->Group->find('all');
$members = $this->Group->GroupMember->find('all', array('order' => array('GroupMember.date_checked DESC'))); //Line 10!
$owners = $this->Group->GroupContact->find('all', array('conditions' => array('GroupContact.owner' => 1)));
$this->set(compact('groups', 'members', 'owners'));
}
It looks like it fails to read GroupMember as an object.
Model – groupMember.php
<?php
class GroupMember extends AppModel{
var $name = 'GroupMember';
var $belongsTo = array(
'Group' => array(
'className' => 'Group',
'foreignKey' => 'group_id'
)
);
}
?>
Model – group.php
<?php
class Group extends AppModel{
var $name = 'Group';
var $hasMany = array(
'GroupMember' => array(
'className' => 'GroupMember',
'foreignKey' => 'id',
)
);
}
?>
You can see the errors on the http://www.thesupergroupproject.com/groups
Again – the project is working both on my localhost and my friend’s localhost. What could be causing the error?
Model names should be
CamelCase. I suspect you are on windows or some other opperating system that iscase insensitive, while your production is Linux which iscase sensitiveAlso when using 2.x there is no need for the $name property in models, this was for PHP4.x support which has been dropped.
Your relation with
'foreignKey' => 'id'seems to be incorrect, GroupMember should be related by thegroup_idfield.