CakePHP在页面顶部显示错误
我正在构建一个CakePHP 2应用程序。我一直在尝试如何最好地在页面顶部显示我的表单错误。我已经找到了一些其他的帖子,它们帮助我得到了错误,但是我正在努力通过它们来正确地显示它们 我的表单由多行字段组成-每行是一个单独的db行(作为费用索赔一部分的单独费用) 我正在控制器中设置此项以传递错误:CakePHP在页面顶部显示错误,cakephp,Cakephp,我正在构建一个CakePHP 2应用程序。我一直在尝试如何最好地在页面顶部显示我的表单错误。我已经找到了一些其他的帖子,它们帮助我得到了错误,但是我正在努力通过它们来正确地显示它们 我的表单由多行字段组成-每行是一个单独的db行(作为费用索赔一部分的单独费用) 我正在控制器中设置此项以传递错误: $this->set('errors', $this->ExpenseClaim->validationErrors); 这将通过以下错误数组传递: array( (int)
$this->set('errors', $this->ExpenseClaim->validationErrors);
这将通过以下错误数组传递:
array(
(int) 0 => array(
'date' => array(
(int) 0 => 'The expense date cannot be blank'
),
'sitename' => array(
(int) 0 => 'The expense sitename cannot be blank'
),
'detail' => array(
(int) 0 => 'The expense details cannot be blank'
),
'amount' => array(
(int) 0 => 'The expense amount cannot be blank'
),
'total' => array(
(int) 0 => 'The expense total should not be blank'
)
),
(int) 1 => array(
'date' => array(
(int) 0 => 'The expense date cannot be blank'
),
'sitename' => array(
(int) 0 => 'The expense sitename cannot be blank'
),
'detail' => array(
(int) 0 => 'The expense details cannot be blank'
),
'amount' => array(
(int) 0 => 'The expense amount cannot be blank'
),
'total' => array(
(int) 0 => 'The expense total should not be blank'
)
)
)
我已经尝试了很多不同的foreach循环来尝试找出错误,但是由于嵌套的级别,我失败了。有人能给我指出正确的方向吗
我只需要一个错误,如“第1行的费用日期不能为空”
我使用jQuery插入行,因此不能依赖表单帮助器
提前谢谢。我把事情复杂化了!希望这可以帮助其他人:
foreach ($errors['Expense'] as $key => $error) {
foreach ($error as $value) {
foreach ($value as $val) { ?>
<li><?php echo $val; ?> in row <?php echo $key; ?></li>
<?php } ?>
<?php } ?>
<?php } ?>
foreach($errors['Expense']as$key=>$error){
foreach($error作为$value){
foreach($val形式的值){?>
在行