私の問題は次のようになります。
人々が1つ以上のイベント(Doodleなど)を選択できる投票アプリを作りたいです。このために、私は投票と呼ばれる関数を設定しました。ビューでは、チェックボックスを使用してイベントを選択できます。モデルはPollとGroupeventです。投票には多くのグループイベントがあります。私の問題は、を呼び出すとupdateAll()
、関連するGroupeventsのすべての値がインクリメントされることです。
これが私のコードです:
意見:
echo $this->Form->create('Poll', array('action' => 'vote'));
for($i=0; $i<$count; $i++){
echo $this->Form->input('Groupevent.'.$i.'.votes', array('type'=>'checkbox',
'label'=>$this->Groupevent['startTime']));
echo $this->Form->input('Groupevent.'.$i.'.id', array('type'=>'hidden'));
}
echo $this->Form->input('id', array('type' => 'hidden'));
echo $this->Form->end('vote');
コントローラ機能:
function vote($id=null){
$this->Poll->id = $id;
if ($this->request->is('get')) {
$this->request->data = $this->Poll->read();
$this->set('count', $this->Poll->Groupevent->find('count',
array('conditions'=>array('Groupevent.poll_id'=>$this->Poll->id))));
} else {
unset($this->Poll->Groupevent->validate['poll_id']);
if ($this->Poll->Groupevent->updateAll(
array('Groupevent.votes'=>'Groupevent.votes+1'),
array('Groupevent.poll_id'=>$this->Poll->id)))
{
$this->Session->setFlash('Your poll has been updated.');
$this->redirect(array('action' => 'edit', $id));
} else {
$this->Session->setFlash('Unable to update your poll.');
}
}
}
チェックされた値だけがインクリメントされるように、どうすればそれを機能させることができますか?
前もって感謝します
編集:
アレイでの提案に感謝します。しかし、私はそれが機能しない特定の方法を試しました。このアレイを作成するにはどうすればよいですか?