doushan1850 2014-10-03 04:23
浏览 30
已采纳

预填充多个记录

I can pre-populate a form of 1 record but i cant get multiple records to pre-populate a form. I want to pre-populate all the records from an ID of which there will be about 6-10 rows.

I get the required form fields to display (about 7 records as expected) but nothing in the textboxes. The docs are not clear about multiple records in this case.

Also I need save only a few of these records

  public function availtmped($id = null) {
     $this->loadModel('AvailabilityForTutor');

   ....
         if ($this->request->is('post')) {
             $this->Availtmp->create();
              $tutoredit = array('Availtmp' => $this->request->data['AvailablityForTutor']);
                 $tutoredit['Availtmp']['id']=NULL;
           $tutoredit['Availtmp']['tutor_id']=$id;;

               if ($this->Availtmp->save($tutoredit)) {
                $this->Session->setFlash(__('The tutor details to be edited have ben forwarded to management'), 'flash_success');
               // $this->redirect(array('controller'=> 'tutors' , 'action' => 'tutordetails'));
            } else {
                $this->Session->setFlash(__('The tutor edit details could not be saved. Please, try again.'), 'flash_alert');
            }
        } else {
           // $this->request->data = $this->AvailablityForTutor->read(null, $id);
        }

      $tutor_id = $id;
        $tutor =$this->AvailabilityForTutor->find('all',array(  'conditions'=>array('tutor_id'=> $tutorId)));
        $this->request->data=$tutor;

view//  UPDATE - I can populate with weekday but not time field as I just get the wrong start/end time

      echo $this->Form->create('AvailablityForTutor', array('type' => 'post'));  

             foreach ($tutor as $key => $item):
          echo $this->Form->input('AvailabilityForTutor.'.$key.'.weekday', 
                                    array('value'=>$this->request->data[$key]        echo $this->Form->input('weekday', 
                                        array('value'=>$this->request->data[$key]['AvailabilityForTutor']['weekday']));
               echo $this->Form->input('start_time', 
                                        array('value'=>$this->request->data[$key]['AvailabilityForTutor']['start_time']));

              echo $this->Form->input('end_time', 
                                        array('value'=>$this->request->data[$key]['AvailabilityForTutor']['end_time']));


           echo $this->Form->end('Save Edit Request');
  • 写回答

1条回答 默认 最新

  • douwen5741 2014-10-03 05:16
    关注

    Use the below method it is very basic but you can follow through it

     foreach ($tutor as $key => $item):
          echo $this->Form->input('AvailabilityForTutor.'.$key.'.weekday', array('value'=>$this->request->data[$key]['AvailabilityForTutor']['weekday']));
          echo $this->Form->hidden('AvailabilityForTutor.'.$key.'.id', array('value'=>$this->request->data[$key]['AvailabilityForTutor']['id']));
     endforeach;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重