我有以下模型:
class Adjustment extends AppModel {
var $name = 'Adjustment';
var $belongsTo = array(
'Source_Budget'=>array('className'=>'Budget','foreignKey'=>'s_budget_id'),
'Target_Budget'=>array('className'=>'Budget','foreignKey'=>'t_budget_id'),
'Source_Project'=>array('className'=>'Project','foreignKey'=>'s_project_id'),
'Target_Project'=>array('className'=>'Project','foreignKey'=>'t_project_id')
);
模型预算和项目如下
class Budget extends AppModel {
var $name='Budget';
var $belongsTo = array('Year');
var $hasMany=array('Project','Payment','Revenue',
'AdjustmentFrom'=>array('className'=>'Adjustment','foreignKey'=>'s_budget_id'),
'AdjustmentTo'=>array('className'=>'Adjustment','foreignKey'=>'t_budget_id'),
'TransferFrom'=>array('className'=>'Transfer','foreignKey'=>'s_budget_id'),
'TransferTo'=>array('className'=>'Transfer','foreignKey'=>'t_budget_id')
);
class Project extends AppModel {
var $name = 'Project';
var $belongsTo = array('Budget','Year');
var $hasMany=array('Payment','Revenue',
'AdjustmentFrom'=>array('className'=>'Adjustment','foreignKey'=>'s_project_id'),
'AdjustmentTo'=>array('className'=>'Adjustment','foreignKey'=>'t_project_id'),
'TransferFrom'=>array('className'=>'Transfer','foreignKey'=>'s_project_id'),
'TransferTo'=>array('className'=>'Transfer','foreignKey'=>'t_project_id')
);
我已经成功地创建了一个带有脚手架的控制器,它添加/删除/更新调整,但是当我烘焙代码时,当我尝试添加调整时,我收到消息“错误:调用非对象上的成员函数 find()”。
错误在以下行:
$sourceBudgets = $this->Adjustment->SourceBudget->find('list');
$targetBudgets = $this->Adjustment->TargetBudget->find('list');
$sourceProjects = $this->Adjustment->SourceProject->find('list');
$targetProjects = $this->Adjustment->TargetProject->find('list');
$this->set(compact('sBudgets', 'tBudgets', 'sProjects', 'tProjects'));
场外没有模型 SBudget、TBudget、SProject、TProject 所以我编辑了如下代码:
$sourceBudgets = $this->Adjustment->Budget->find('list');
$targetBudgets = $this->Adjustment->Budget->find('list');
$sourceProjects = $this->Adjustment->Project->find('list');
$targetProjects = $this->Adjustment->Project->find('list');
$this->set(compact('sBudgets', 'tBudgets', 'sProjects', 'tProjects'));
我添加了行 public $uses = array('Budget', 'Project');
在调整控制器类中。不幸的是,问题仍然存在,我总是收到“错误:在非对象上调用成员函数 find()”消息。