2
동일한 테이블에 여러 항목이있는 양식이 있습니다. 문제는 데이터베이스에 마지막 항목 만 보내고 나머지는 보내지 않는다는 것입니다. 디버그를 사용하고 양식의 마지막 필드 만 인쇄합니다. field
반복 될 때마다데이터베이스에 배열 저장 cakephp
는이 fields_invoices
표에 입력 의미 invoice_id, field_id, entered_value
여기 여기 내 형태
<?php echo $this->Form->create('FieldsInvoice'); ?>
<?php foreach ($fields as $field): ?>
<?php echo $this->Form->hidden('FieldsInvoice.id'); ?>
<?php echo $this->Form->hidden('FieldsInvoice.field_id', array('default' =>$field['Field']['id'])); ?>
<?php echo $this->Form->input('FieldsInvoice.invoice_id', array('default' =>$invoice_id, 'type'=>'hidden')); ?>
<?php echo $this->Form->Input('FieldsInvoice.entered_value', array('label'=>$field['Field']['name'], 'default' =>$field['Field']['default_value'])); ?>
<?php endforeach ;?>
<?php echo $this->Form->End('Submit');?>
인 관련 컨트롤러를 인
public function create($id)
{
$this->set('title_for_layout', 'Create Invoice');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.png');
$this->layout='home_layout';
if (!is_numeric($id)) throw new BadMethodCallException('I need an ID');
$this->Invoice->id = $id;
if (!$this->Invoice->exists()) throw new NotFoundException('Invalid ID');
$this->set('invoice_id',$id);
$names = $this->Invoice->find('list',array(
'fields'=>array('template_id'),
'conditions'=>array('id'=>$id)));
$fields = $this->Field->find('all', array(
'conditions'=>array(
'template_id'=>$names)));
$this->set(compact('fields'));
$this->set(compact('invoice_id'));
$this->set('name',$names);
$this->Invoice->create();
if(empty($this->data)){
$this->data= $this->Field->read($id);
}
else{
if($this->request->is('post'))
{
//die(debug($this->data));
$this->Invoice->create();
if($this->FieldsInvoice->save($this->request->data, array('deep'=>true)));
{
$this->Session->setFlash('The field has been updated');
$this->redirect(array('controller'=>'invoices', 'action'=>'index'));
}
//else{
$this->Session->setFlash('Could not be saved');
//}
}
}
}
\app\Controller\InvoicesController.php (line 134)
array(
'FieldsInvoice' => array(
(int) 0 => array(
'id' => '',
'field_id' => '0',
'invoice_id' => '97',
'entered_value' => '1'
),
(int) 1 => array(
'id' => '',
'field_id' => '99',
'invoice_id' => '97',
'entered_value' => '2'
),
(int) 2 => array(
'id' => '',
'field_id' => '999',
'invoice_id' => '97',
'entered_value' => '3'
),
(int) 3 => array(
'id' => '',
'field_id' => '9999',
'invoice_id' => '97',
'entered_value' => '4'
)
)
)
저장하지 않지만 내 디버그로 질문을 업데이트했습니다. – user1393064
점을 잊어 버렸습니다. 예를 들어, 디버그에서'3entered_value'는''FieldsInvoice. '. $ idx.'. entered_value '대신''FieldsInvoice.'$ idx.'entered_value''를 쓴다는 것을 의미합니다. – ori
은 새로운 배열 인쇄물로 업데이트되었지만 이제는 내 databse에 아무 것도 저장하지 않습니다. – user1393064