0

好的,这是测试控制器:

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

其他观点可能并不重要。但如果他们是我会复制他们。

你能说出为什么它不能按预期显示吗?

4

1 回答 1

0

发现问题 - 没有使用 test/filteredData/form.blade.php 中的数据

不得不说:

{{ $filteredData; }}
于 2013-10-28T10:27:02.523 回答