我有两个控制器“事件”和“活动”,两者都有许多“与会者”。
$this->hasMany('Attendees')
->setClassName('Attendees')
->setForeignKey('foreign_id')
->setConditions(array('Attendees.class' => 'Activity'))
->setDependent(true);
我正在使用Attendees表中的一个类和一个foreign_id来链接它们。例如,我想在ActivitiesController中创建addAttendee()函数来添加一个新的与会者,但我不确定如何继续。
public function addAttendee($id = null)
{
$activity = $this->Activities->get($id, ['contain' => ['Venues', 'Contacts']]);
if ($this->request->is('post'))
{
??
}
$this->set(compact('activity'));
}
我找到了一些关于保存关联的文档,但没有关于创建新关联的文档。
2条答案
按热度按时间uajslkp61#
您可以创建一个新的
Attendee
实体,然后将其链接到您的$activity
。这是一个很好的例子,因为它是一个很好的例子。
8xiog9wr2#
我是这样做的。这是工作,但不确定这是否是正确的方式进行?