Tuesday, 10 September 2013

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

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

I think I have a quiet simple error but i can't solve it... I try to
associate two tables:

projects hasMany keywords
keywords belogsTo projects
My code:
<?php
class KeywordsController extends AppController{
public function add(){
$projects = $this->Keyword->Project->find('list'); //***here is
the error***
//pr($projects);
if ($this->request->is('post')) {
$this->Keyword->save($this->request->data);
$this->redirect('/keywords');
}
}
}



<?php
class ProjectsController extends AppController{
public function add(){
if ($this->request->is('post')) {
$this->Project->save($this->request->data);
$this->redirect('/projects');
}
}
}



<?php
class Project extends AppModel{
public $hasMany = 'Keyword';
}



<?php
class Keyword extends AppModel{
public $belongsTo = 'Project';
}
Error message:
Error: Call to a member function find() on a non-object
File: /Users/me/Localhost/cakephp/app/Controller/KeywordsController.php
Line: 7

No comments:

Post a Comment