2017-05-24 2 views
-2

데이터베이스의 데이터로 채워진 양식이 각 레코드의 라디오 목록 단추와 함께 있습니다. 체크하고 양식을 제출 한 후에 마지막 레코드 만 데이터베이스에 저장되지만 모든 레코드가 저장되기를 원합니다. 다음은 내 코드입니다 : // 양식 코드 페칭/데이터베이스를 조회하나의 양식을 사용하여 동일한 데이터베이스에 여러 레코드를 제출할 수 없습니다.

<?php $form = ActiveForm::begin(); ?> 
    <?= $form->field($model, 'class')->label('Class')->dropDownList(
      Arrayhelper::map(Classes::find()->all(), 'class_name', 
    'class_name'), 
      [ 
       'maxlength' => true, 
       'style'=>'width: 300px; height: 50px;', 
       'prompt'=>'select class', 
       'onchange'=>' 
        $.post("index.php? 
    r=attendance/list&id='.'"+$(this).val(), function(data){ 
        $("section#Attend").html(data); 
        });' 
       ]); ?> 

// 가져 와서에서 폼에

public function actionList($id){ 
     $model = new Attendance; 
     $form = new ActiveForm; 

     $countclass = Registrationinfo::find() 
       ->where(['current_class' => $id]) 
       ->count(); 
     $lga = Registrationinfo::find() 
       ->where(['current_class' => $id]) 
       ->all(); 
     if($countclass > 0){ 
      foreach($lga as $data){ ?> 
       <div > 
      <div class="col-md-1"><?= ('1')?></div> 
      <div style="display: inline;"><?= $data['first_name'] ?></div> 
      <div style="display: inline; margin-left: 20px;"><?= 
$data['surname'] ?></div> 
      <div style="display: inline; margin-left: 79px;"><?= 
    $data['gender'] ?></div> 
      <div style="display: inline; margin-left: 20px;"><?= $form- 
    >field($model, 'student_id')->textInput(['value'=>$data->reg_no, 
    'disabled'=>''])->label(false) ?></div> 
      <div style="display: inline; margin-left: 150px;"> <?= $form- 
    >field($model, 'status') 
    ->radioList(array('PR' => 'Present', 'PM' =>'Permission', 'LT' 
    =>'Late', 'AB' =>'Absent'), array('class' => 'i-checks')); ?> 
       <hr style="color: blue;"> 
     <?php 
      } 
     } 
     else{ 
      echo "<div class=>'info'>Invalide Class name </div>"; 
     } 
    } 

// 내 actionCreate을 결과를 전송 컨트롤러 코드 같은 컨트롤러

public function actionCreate() 
    { 
     $model = [new Attendance()]; 
     //select date from datesetup where status is open 
     $date = DateSetup::findbysql('SELECT date from date_setup WHERE 
    status = "open"')->all(); 
     if(count($date) > 0){ 
      foreach ($date as $dates); 
     }else{ 
      echo "No date As been opened yet"; 
     } 
     //select Term from Termsetup where status is open 
     $terms = Termsetup::findbysql('SELECT term from termsetup WHERE 
    status = "open"')->all(); 
     if(count($terms) > 0){ 
      foreach ($terms as $term); 
     }else{ 
      echo "No Term As been opened yet"; 
     } 

     if ($model->load(Yii::$app->request->post()) && $model->validate()) 
    { 
    //adding the database value retrive to the attandance form field  
      $model->term = $term->term; 
      $model->day = date('d', strtotime('$dates')); 
      $model->month = date('m', strtotime('$dates')); 
      $model->year = date('Y', strtotime('$dates')); 
      $model->date = date('Y-m-d h:m:s'); 
      $model->user_id = "admin"; 
      if (isset($_POST['student_id'])) { 
    $model->student_id = $_POST['student_id']; 
    // validate, save or more.. 
    } 
    else { 
     echo "reg_no not posted"; //return array 
    } 
      //$model->student_id = $data->student_id; 
      //$model->user_id = Yii::$app->user->identity->user_id; 
      if($model->save()) 

     return $this->redirect(['view', 'id' => $model->id]); 
     } 
     return $this->render('create', [ 
      'model' => $model, 
      ]); 
    } 
+0

직접 디버깅을해야합니다.이 코드를 모두 읽지 않아도 작동하지 않는 코드를 찾아 낼 수는 없습니다. 오류보고를 켜고 로그를 확인하십시오. – Epodax

+0

문제는 첫 번째 라디오 버튼을 누른 후 두 번째 것 (다음 레코드에서)을 틱하면 첫 번째 버튼이 자동으로 @Epodax –

답변

0

양식의 이름 속성을 업데이트로 삽입하여 양식의 모든 요소 (각 항목에 사용)와 모든 요소에 대해 insert/update 문을 실행하십시오.

+0

yii 프레임 작업에 새로운 종류인지 확인하지 않고 약간 어려움이있을 수 있습니다. 어떻게 선언해야 하는가 @ S.Kartik –

+0

샘플 코드 : foreach ($ hours = $ $ 값) { # 코드 ... // echo $ value"- ". $ date [$ key]. "\ n"; $ enter_date = $ date [$ key]; // $ sql_statement = –