我有多条记录我无法保存。发生的事情是只保存最后一条记录而不保存其他记录。 我也试图从每条记录中删除id。我试过SaveAll,SaveMany等
http://book.cakephp.org/2.0/en/models/saving-your-data.html
控制器
if ($this->request->is('post')) {
$this->Availtmp->create();
$tutoredit = array('Availtmp' => $this->request->data);
debug($tutoredit) ;
$tutoredit['Availtmp']['id']=NULL;
$tutoredit['Availtmp']['tutor_id']=$id;;
if ($this->Availtmp->save($tutoredit)) {
$this->Session->setFlas.....
}
查看
foreach ($tutor as $key => $item):
echo $this->Form->input('AvailabilityForTutor.'.$key.'weekday',
array('value' => $this->request->data[$key]['AvailabilityForTutor']['weekday'])
);
echo $this->Form->input('AvailabilityForTutor.'.$key.'start_time',
array('type' => 'time', 'selected'=>$this->request->data[$key]['AvailabilityForTutor']['start_time'])
);
echo $this->Form->input('AvailabilityForTutor.'.$key.'end_time',
array('type' => 'time','selected'=>$this->request->data[$key]['AvailabilityForTutor']['end_time'])
);
echo $this->Form->hidden('AvailabilityForTutor.'.$key.'.id',
array('value' => $this->request->data[$key]['AvailabilityForTutor']['id'])
);
endforeach;
echo $this->Form->end('Save Edit Request');
**data**array(
'Availtmp' => array(
'AvailabilityForTutor' => array(
(int) 0 => array(
'weekday' => 'Monday',
'start_time' => array(
'hour' => '09',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '11',
'min' => '00',
'meridian' => 'pm'
),
'id' => '99'
),
(int) 1 => array(
'weekday' => 'Tuesday',
'start_time' => array(
'hour' => '09',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '10',
'min' => '00',
'meridian' => 'pm'
),
'id' => '100'
),
(int) 2 => array(
'weekday' => 'Wednesday',
'start_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'id' => '101'
),
(int) 3 => array(
'weekday' => 'Thursday',
'start_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'id' => '102'
),
(int) 4 => array(
'weekday' => 'Friday',
'start_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'id' => '103'
),
(int) 5 => array(
'weekday' => 'Saturday',
'start_time' => array(
'hour' => '09',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '11',
'min' => '00',
'meridian' => 'pm'
),
'id' => '104'
),
(int) 6 => array(
'weekday' => 'Sunday',
'start_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'end_time' => array(
'hour' => '12',
'min' => '00',
'meridian' => 'am'
),
'id' => '105'
)
答案 0 :(得分:1)
你试过吗
$this->Availtmp->saveAll($this->request->data['AvailabilityForTutor']);
你错过了一个点
echo $this->Form->input('AvailabilityForTutor.'.$key.'weekday',
应该是
echo $this->Form->input('AvailabilityForTutor.'.$key.'.weekday',
你错过了你的ctp中的每一行,除了字段id