Reputation: 195
I'm trying to display all my data in a table name contacts but it gives me an error Call to a member function find() on null. I don't understand what it means. Please help!
<?php
class ContactsController extends AppController {
var $name = "Contacts";
public function index() {
$this->set('contacts', $this->Contacts->find('all'));
}
}
?>
Upvotes: 3
Views: 18335
Reputation: 5270
You have to use the below code in the header section in your controller
public $uses = array('Your_Model_Name'); // array('User');
Upvotes: 0
Reputation: 447
In your controller use the variable $use as follows
$use = array ('model_name');
Only that
Upvotes: 0
Reputation: 785
In your controller.
<?php
class ContactsController extends AppController {
public function index() {
$this->set('contacts', $this->Contact->find('all')); // here the change Contacts to Contact.
}
}
?>
Your Model.
<?php
class Contact extends AppModel {
var $name = "Contact";
}
?>
Upvotes: 3