我想我有一个安静的简单错误,但我无法解决它......我尝试关联两个表:
- 项目有很多关键词
- 关键字belogsTo项目
我的代码:
<?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';
}
错误信息:
错误:在非对象
文件上调用成员函数 find():/Users/me/Localhost/cakephp/app/Controller/KeywordsController.php
行:7