2012-07-04 2 views
1

나는 학생이 드롭 다운 목록을 사용하여 과목을 입력하는 형식을 가지고 있습니다. 드롭 다운 목록은 표에서 주제를 가져옵니다. 이 드롭 다운의 유효성을 검사하여 학생이 한 번만 주제를 선택하도록합니다. 과목이 반복되고 있습니다. 내가 어떻게 할 수 있니?Cakephp : 배열 요소의 유효성 확인

내 컨트롤러

for ($i = 1; $i < sizeof($this->data['ApplicantOlevelQualification']['olevel_subject_code']); $i++) { 

       if ($this->data['ApplicantOlevelQualification']['olevel_subject_code'][$i] != "") { 
        $this->ApplicantOlevelQualification->create(); 
        $this->ApplicantOlevelQualification->id = null; 
        $this->ApplicantOlevelQualification->set(array(
          'applicants_detail_id' => $app_id, 
          'olevel_subject_code' => $this->data['ApplicantOlevelQualification']['olevel_subject_code'][$i], 
          'grade' => $this->data['ApplicantOlevelQualification']['grade'][$i], 
          'mark' => $this->data['ApplicantOlevelQualification']['mark'][$i], 
          'centre_number'=> $centre_number, 
          'candidate_number'=> $candidate_number, 
          'exam_body_code'=> $exam_body_code, 
          'year_written'=> $year_written, 

         ) 
        ); 

내 add.ctp

echo "<tr><td>" . $this->Form->label('Subject: '); 
     echo "</td><td>"; 
     echo $this->Form->select("ApplicantOlevelQualification.olevel_subject_code.$s",$mySubjects); 
     echo "</td><td>"; 

모델

'olevel_subject_code' => array(
     'numeric' => array(
      'rule' => array('valids'), 
         ), 
    ), 
+0

$ mySubjects에서 드롭 다운 제목을 고유하게 지정해야합니다. $ mySubjects 코드를 보여줄 수 있습니까? –

+0

Moyed에 응답 해 주셔서 감사합니다. Add.ctp $ mySubjects = $ subjects; 컨트롤러 $ subjects- $ this-> ApplicantOlevelQualification-> OlevelSubject-> find ('list', array ('fields'=> array ('code', 'name')))); – alicemap

답변

0

이 드롭 다운 목록에 GROUP BY를 추가하여 고유 수

$subjects = $this->ApplicantOlevelQualification->OlevelSubject->find('list',array('fields'=>‌​array('code','name'),'group'=>array(code))); 
,