Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to a member function find() on null CakePHP

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'));
            }
        }
?>
like image 459
PHP.Newbie Avatar asked Feb 04 '26 00:02

PHP.Newbie


1 Answers

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";
    }
?>
like image 197
Sainesh Mamgain Avatar answered Feb 09 '26 01:02

Sainesh Mamgain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!