我对 cakephp 中的 HABTM 关系有疑问。我有 2 个模型 Campaign 和 Person 我创建了 3 个数据库表campaings、persons 和campaigns_persons。
模型如下所示:
活动
class Campaign extends AppModel {
var $name = 'Campaign';
var $displayField = 'nombre';
var $belongsTo = array(
'Client' => array(
'className' => 'Client',
'foreignKey' => 'client_id'
),
'Template' => array(
'className' => 'Template',
'foreignKey' => 'template_id'
)
);
var $hasAndBelongsToMany = array(
'Persona' =>
array('className' => 'Person',
'joinTable' => 'campaigns_persons',
'foreignKey' => 'campaign_id',
'associationForeignKey' => 'person_id',
'with' => '',
'conditions' => '',
'order' => '',
'limit' => '',
'unique' => true,
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
}
人
class Person extends AppModel {
var $name = 'Person';
var $displayField = 'name';
var $belongsTo = array(
'Client' => array(
'className' => 'Client',
'foreignKey' => 'client_id',
),
);
}
控制器如下所示:
$this->Campaign->create();
if ($this->Campaign->save($this->data)) {
$this->Session->write('campaign_id', $this->Campaign->id);
$this->Session->setFlash(__("Listado de clientes agregado", true));
return true;
}//fin saveAll
它向我抛出了这个错误:
Fatal error: Cannot access empty property in
1 0.0012 372600 {main}( ) ..\index.php:0
2 0.1148 4012344 Dispatcher->dispatch( ) ..\index.php:86
3 0.1319 4967600 Dispatcher->_invoke( ) ..\dispatcher.php:171
4 2.2085 9815800 call_user_func_array ( ) ..\dispatcher.php:204
5 2.2085 9815968 CampaignsController->end_campaign( ) ..\dispatcher.php:204
6 2.4742 9845328 CampaignsController->__saveAll( ) ..\campaigns_controller.php:221
7 2.4743 9845568 Model->save( ) ..\campaigns_controller.php:281
我不知道发生了什么。