我正在使用具有多个同名字段的表单。在对表单进行错误验证后,我将使用验证消息返回给它。这一切都有效。虽然字段的验证消息显示正确,但字段中输入的数据却消失了。
它的 cakephp 2.2 应用程序没有数据库。(将数据保存到 3 页的会话中,然后将其写入 XML)
step2.ctp:
debug($this->Form);
echo $this->Form->input('Invoice.0.InvoiceOrderNumber', array('label' => false));
echo $this->Form->input('Invoice.0.NetAmount', array('label' => false));
echo $this->Form->input('Invoice.0.CostBearer', array('label' => false));
echo $this->Form->input('Invoice.0.CostCenter', array('label' => false));
echo $this->Form->input('Invoice.0.LedgerAccount', array('label' => false));
控制器:
public function step2() {
$invoice = $this->Session->read('Invoice');
if (!isset($invoice) && is_array($invoice))
$this->redirect(array('action' => 'step1'));
else
{
$this->set('title_for_layout', 'Nieuwe interne doorbelasting');
if ($this->request->is('post')) {
debug($this->request->data);
if ($this->Invoice->validateMany($this->request->data['Invoice']))
{
if ($this->Session->write('Invoice', $this->request->data['Invoice'])) {
$this->Session->setFlash(__('The invoice has been saved'));
$this->redirect(array('action' => 'step3'));
} else {
$this->Session->setFlash(__('The invoice could not be saved. Please, try again.'));
}
}
}
}
}
step2.ctp 中 ($this->Form) 的调试:
.....
request => object(CakeRequest) {
params => array(
'plugin' => null,
'controller' => 'invoices',
'action' => 'step2',
'named' => array(),
'pass' => array(),
'models' => array(
'Invoice' => array(
'plugin' => null,
'className' => 'Invoice'
)
)
)
data => array(
'Invoice' => array(
(int) 0 => array(
'Invoice' => array(
'InvoiceOrderNumber' => 'adfas',
'NetAmount' => '2',
'CostBearer' => '',
'CostCenter' => '',
'LedgerAccount' => ''
)
),
(int) 1 => array(
'Invoice' => array(
'InvoiceOrderNumber' => 'adaaaaaaaaa',
'NetAmount' => 'bbbbbbbbb',
'CostBearer' => '',
'CostCenter' => '',
'LedgerAccount' => ''
)
)
)
)
....
所以数据在那里,但蛋糕没有把它放在字段中。但我想不通为什么...