这是我的模特
<?php
class Survey extends AppModel {
// model associations
public $belongsTo = array(
'Organisation' => array(
'className' => 'Organisation',
'foreignKey' => 'organisation_id'
),
'Account' => array(
'className' => 'Account',
'foreignKey' => 'account_id'
),
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id'
),
'Country' => array(
'className' => 'Country',
'foreignKey' => 'country_id'
),
'Currency' => array(
'className' => 'Currency',
'foreignKey' => 'currency_id'
)
);
}
?>
这是我的控制器
<?php
class SurveysController extends AppController {
public $components = array('Session');
public $uses = array('Report', 'Mycase', 'Workflow');
public function add($type = null, $id = null) {
if (!$id || !$type) {
throw new NotFoundException(__('Invalid link'));
}
$type = Inflector::camelize($type);
// this populates the form select for country allowing the country from the report to be prepopulated
$countries = $this->$type->Country->find('list');
$this->set(compact('countries'));
// this populates the form select for currency
$currencies = $this->Survey->Currency->find('list');
$this->set(compact('currencies'));
$resources = $this->$type->find('first',
array(
'conditions' => array($type.'.id' => $id, $type.'.account_id' => $this->Session->read('Auth.User.account_id')),
'recursive' => -1 //int
));
if (!$resources) {
throw new NotFoundException(__('You are not authorised to access that location'));
}
$this->set('resources', $resources);
}
}
错误在于控制器中的这行代码
$currencies = $this->Survey->Currency->find('list');
我有一个带有Currencies的数据库表,我正在尝试将其填充到选择中的Survey视图中。我已检查模型和控制器是否正确命名。我的关联类似于我也使用的国家/地区选择,它正常工作,但我在货币查询中收到此错误,我一直在尝试调试几个小时。
Fatal Error
Error: Call to a member function find() on a non-object
File: C:\xampp\htdocs\cakephp2-5-3\app\Controller\SurveysController.php
Line: 29
答案 0 :(得分:0)
错误消息告诉您要查看的位置: SurveysController.php 的第29行。
您有可能在未包含的模型上调用find()
。如果是Survey
,则需要将其添加到控制器中的$uses
属性,以便加载它。