Skip to content

Instantly share code, notes, and snippets.

@cholnhial
Created June 16, 2015 08:16
Show Gist options
  • Save cholnhial/d741469e5b6599dc3483 to your computer and use it in GitHub Desktop.
Save cholnhial/d741469e5b6599dc3483 to your computer and use it in GitHub Desktop.
public function stock($id = null)
{
$fabric = $this->Fabrics->get($id, ['contain' => ['FabricColours']]);
if($this->request->is('post'))
{
$list = $this->Fabrics->FabricColours->find('all')->where(['fabric_id' => $id])->toArray();
$fabricColours = $this->Fabrics->patchEntities($list, $this->request->data('data'));
$data = $this->request->data['data'];
$countOf = count($fabricColours);
$this->set(array('data' => $data,'fabricColours' => $fabricColours,'list' => $list, 'countOf' => $countOf, '_serialize' => ['data', 'countOf', 'fabricColours', 'list']));
return;
foreach($fabricColours as $fabricColour)
{
$this->Fabrics->FabricColours->save($fabricColour);
}
}
$this->set('title', 'Colour stocks for ' . $fabric->name);
$this->set('_serialize', 'fabric');
$this->set(compact('fabric'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment