我可以预先填充1条记录的形式,但我无法获得多条记录来预先填充表格。 我想预先填充ID中的所有记录,其中大约有6-10行。
我得到所需的表单字段(按预期大约有7条记录),但文本框中没有任何内容。 在这种情况下,文档不清楚多个记录。
此外,我只需保存其中一些记录
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');
答案 0 :(得分:0)
使用以下方法,这是非常基本的,但你可以通过它
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;