好的,这是测试控制器:
class TestController extends BaseController {
public function __construct() {
ini_set("display_errors", true);
}
private $turnoverPerFranchise = array(
0 => 't1',
1 => 't2'
);
private $turnoverPerShop = array(
0 => 's1',
1 => 's2'
);
public function getTurnover() {
$formData = array();
$formData['shops'] = 'shosp dropdown';
$form = View::make('test.form', $formData);
$data2['content'] = $form;
return View::make('test/template', $data2);
}
public function postTurnover() {
echo 'post';
$formData = array('a');
$formData['filteredData'] = $this->getFiltered();
// if not set index shops. then it displays error - its how is expected
$data['content'] = View::make('test.form', $formData);
return View::make('test/template', $data);
}
private function getFiltered() {
$data2['totalsTable'] = $this->getTotalsView();
$data2['franchiseBlocks'] = array();
foreach ($this->turnoverPerFranchise as $franchiseId => $franchiseTurnover) {
$franchiseData['franchise'] = $franchiseTurnover;
$franchiseData['systemCurrency'] = '$';
$franchiseData['shopViews'] = array();
foreach ($this->turnoverPerShop as $shopId => $shopTurnover) {
if ($shopTurnover['franchiseId'] == $franchiseId) {
$franchiseData['shopViews'][] = 'shop view';
}
}
$data2['franchiseBlocks'][] = View::make('test.filteredData.franchise', $franchiseData);
//$data2['franchiseBlocks'][] = 'aa';
}
echo count($data2['franchiseBlocks']) . '<br>';
return View::make('test.filteredData.main', $data2); // same
}
/**
* Gets table of filteredData totals
* @return object
*/
private function getTotalsView() {
$dataTotals = array();
$dataTotals['totals'] = 'bla bla bla';
$dataTotals['systemCurrency'] = '$';
return View::make('test.filteredData.totalsTable', $dataTotals);
}
public function getMain() { // works
$data2['franchiseBlocks'] = array(1 => 'a');
return View::make('test.filteredData.main', $data2); // the same view in getFiltered is not displayed
}
}
如果我调用函数postTurnover()
然后呈现
post2和提交按钮。 2意味着有两个项目可以在foreach循环中运行。
当我运行函数getMain()
时然后视图渲染完全正常。
查看test / filteredData / main.blade.php很简单:
<br>
main
@foreach ($franchiseBlocks as $franchise)
<strong>franchise block</strong>
{{ $franchise }}
@endforeach
查看test / filteredData / franchise.blade.php
franchise
@foreach ($shopViews as $shop)
<strong>aaa</strong>
@endforeach
其他观点可能并不重要。但如果他们是我会复制他们。
你能告诉为什么它不能按预期显示吗?
答案 0 :(得分:0)
发现问题 - 没有在test / filteredData / form.blade.php中使用该数据
不得不放:
{{ $filteredData; }}