【发布时间】:2017-05-04 15:35:15
【问题描述】:
我想知道这个函数有什么问题,我只需要更新表中的一个字段或多个关联表中的所有字段。 多重更新工作正常,但是当我只更新第一列时,它对我来说不能正常工作
public function edit($id) {
$contractor = $this->Contractors->get($id);
$associated = ['ContractorsAttachments' ];
// Used to get the all attachments associated with Contractors
$ContractorsAttachments = $this->Contractors->ContractorsAttachments->find()->where(['contractor_id' => $id])->all();
if ($this->request->is(['patch', 'post', 'put'])) {
$contractor = $this->Contractors->patchEntity($contractor, $this->request->data );
if ($this->Contractors->save($contractor)) {
$this->Flash->success(__('The Contractors has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The Contractors could not be saved. Please, try again.'));
}
$this->set(compact('contractor','ContractorsAttachments'));
$this->set('_serialize', ['contractor']);
$this->render('add');
}
【问题讨论】:
-
$associated = ['ContractorsAttachments' ]有什么用
标签: php mysql cakephp cakephp-3.0