0
私のテーブルのカテゴリには、新しい製品が作成されるたびに更新したいcountという行がありますが、このcakephpを初めて使用していて、2コントローラを同時に使用することができます。製品を追加するときにカウンタを追加する
それは私の製品コントローラに追加します。(デフォルトは焼くと作成追加される)
public function add()
{
$product = $this->Products->newEntity();
if ($this->request->is('post')) {
$product = $this->Products->patchEntity($product, $this->request->getData());
if ($this->Products->save($product)) {
$this->Flash->success(__('The product has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The product could not be saved. Please, try again.'));
}
$categorys = $this->Products->Categorys->find('list', ['limit' => 200]);
$this->set(compact('product', 'categorys'));
$this->set('_serialize', ['product']);
}
各製品は、関連するカテゴリがあります。