Cameron
Cameron

Reputation: 28783

CakePHP: Call to a member function find() on a non-object

I get the following errors when viewing my Admin Index

Notice (8): Undefined property: ClientsController::$Clients [APP/controllers/clients_controller.php, line 27]

Call to a member function find() on a non-object in /Users/cameron/Sites/crm/app/controllers/clients_controller.php on line 27

here is the code:

class ClientsController extends AppController
{
    var $name = 'Clients';

    function beforeFilter()
    {
        parent::beforeFilter();
        $this->Auth->allow(array('*'));  
    }

    function index()
    {
        $this->set('clients', $this->Clients->find('all'));
    }

    function view ( $id, $slug )
    {
        $article = $this->Clients->read(null, Tiny::reverseTiny($id));

        $this->set(compact('client'));
    }

    function admin_index()
    {
        $this->set('clients', $this->Clients->find('all'));
    }

Any ideas what the issue is here? (I have created a Model also)

Upvotes: 2

Views: 36483

Answers (2)

禪 師 無
禪 師 無

Reputation: 422

Some potential issues:

Normally

var $name = 'Client'; // Not Clients

You have a Client, and the controller is for "Clients".

Try:

$this->set('clients', $this->Client->find('all'));

with the above suggestion on var $name.

See a more complete list of potential solutions here if that doesn't lead you down the right path.

CakePHP call to member function on non-object

Upvotes: 4

dhofstet
dhofstet

Reputation: 9964

Model names are singular in CakePHP (at least if you follow the naming conventions), which means you have to use: $this->Client->find('all');

Upvotes: 1

Related Questions