ここにテストコントローラーがあります:
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 ループで実行するビューの項目が 2 つあることを意味します。
関数 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
他のビューはおそらく重要ではありません。しかし、もしそうなら、私はそれらをコピーします。
期待どおりに表示できない理由を教えてください。