2014-06-24 7 views
0

내보기 코드는 여기에 ... 컨트롤러에 대한 코드는 무엇입니까, plz 누구든지 설명 할 수 있습니다.cakephp에서 라디오 버튼을 선택한 후 값을 제출하는 방법은 무엇입니까?

<td><?php $attributes = array(); 
     $options = array($question['Question']['opt1']); 
     echo $this->Form->radio($i, $options, $attributes);?>&nbsp;</td> 


    <td><?php $attributes = array(); 
     $options = array($question['Question']['opt2']); 
     echo $this->Form->radio($i, $options, $attributes);?>&nbsp;</td> 


    <td><?php $attributes = array(); 
     $options = array($question['Question']['opt3']); 
     echo $this->Form->radio($i, $options, $attributes);?>&nbsp;</td> 

    <td><?php $attributes = array(); 
     $options = array($question['Question']['opt4']); 
     echo $this->Form->radio($i, $options, $attributes);?>&nbsp;</td> 
</tr> 

<?php endforeach; ?> 
<td><?php echo $this->Form->end(__('Submit'),array('controller'=>'question')); ?></td> 
+1

시작 도움 희망); }'그리고 거기에서 가라. – AD7six

답변

0

간단합니다. 질문 컨트롤러에서의 당신의 형태에 제출 가정 해 봅시다 '/ 질문/yourActionMethodName'

과 같이 보여야 코드 :이 필드의 데이터베이스 열 값을 설정 새로운 새로운 기록을 작성해야합니다

public function yourActionMethodName(){ 

    if($this->request->is('post') && !empty($this->request->data)){ 
     $this->Question->create(); //to save a new record 
     $this->Question->save($this->request->data); 
    } 
} 

를 ' opt1 '을 사용자가 선택한 값으로 변경하십시오. 나는 당신이 해결하려고하는 경우가 무엇인지 확신하지 못한다. 이렇게하면 데이터베이스에 저장된 내용을 알 수 있습니다. 이 사례에 대해 더 자세히 설명해 주시면 필요에 맞게 코드를 편집 할 수 있습니다.

0

당신이

<td><?php $attributes = array(); 
     $options = array($question['Question']['opt1']); 
     echo $this->Form->radio('Model.'.$i.'.name', $options, $attributes);?>&nbsp;</td> 


    <td><?php $attributes = array(); 
     $options = array($question['Question']['opt2']); 
     echo $this->Form->radio('Model.'.$i.'.name', $options, $attributes);?>&nbsp;</td> 


    <td><?php $attributes = array(); 
     $options = array($question['Question']['opt3']); 
     echo $this->Form->radio('Model.'.$i.'.name', $options, $attributes);?>&nbsp;</td> 

    <td><?php $attributes = array(); 
     $options = array($question['Question']['opt4']); 
     echo $this->Form->radio('Model.'.$i.'.name', $options, $attributes);?>&nbsp;</td> 
</tr> 

<?php endforeach; ?> 
<td><?php echo $this->Form->end(__('Submit')); ?></td> 

의 모델과 이름을 넣어 필요 컨트롤러에 후에 당신은 당신이 사용 시려면 또는 saveMany의 출발을 사용할 필요가 많은 필드를 저장해야하는 경우

public function Name(){ 

    if($this->request->is('post') && !empty($this->request->data)){ 
     $this->Question->create(); 
     $this->Question->save($this->request->data); 
    } 
} 
+0

답장을 보내 주셔서 감사합니다. 실제로이 테이블의 열에 이러한 라돈 값을 저장하고 싶습니다. 즉 choosen_answer ....이 후 choosen_answer와 correct_answer를 비교하고 싶습니다. – user3760118

0

아니라 당신이 컨트롤러에 모델을로드하여 DB에 새로운 레코드를 생성하십시오.

이제 컨트롤러에 새 기록을 작성하기 전에 모델을로드 할 수

public function NameOfYourFunction(){ 

    $this->loadModel('Question'); 

    if ($this->request->is('post')) {     
      if ($this->Question->save($this->request->data)) { 
        $this->Session->setFlash(__('Information save succesfully.')); 
        return $this->redirect(array('action' => 'index')); 
      } 
     } 

} 

나는 기능 어떤() {디버그 ($ this-> 요청 -> 데이터`당신에게

관련 문제