내 문제는 다음과 같습니다 :CakePHP 증가 값
사람들이 기념일 로고와 같은 하나 이상의 이벤트를 선택할 수있는 투표 응용 프로그램을 만들고 싶습니다. 이를 위해 나는 vote라는 함수를 설정했습니다. 보기에서 이벤트 체크 박스를 사용하여 선택할 수 있습니다. 모델은 투표 및 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.');
}
}
}
난 그냥 체크 값이 증가 얻을 수 있도록이 작동 할 수 있는가? 사전에
감사
편집 : 배열과 제안에 대한
감사합니다. 그러나 나는 그것이 작동하지 않는 특정 방법을 시도했다. 이 배열을 어떻게 만듭니 까?
안녕하세요, 감사이 있으면 알려주세요. 그러나이 데이터에서 배열을 만들 수는 없습니다. 나는 $ this-> data [ 'Groupevent']와 $ this-> data [ 'Groupevent'] [ 'id']와 다른 것들을 시도했지만 작동하지 않았다. – ulanBator
제출 후 print_r ($ this-> data) 덤프를 붙여 주실 수 있습니까? – bbb
나는 이것을 시도했지만 비어있다. – ulanBator