尝试将多个变量分配给刀片模板

Posted

技术标签:

【中文标题】尝试将多个变量分配给刀片模板【英文标题】:Trying to assign multiple variable to blade template 【发布时间】:2014-06-30 06:06:35 【问题描述】:

我正在,但它返回异常

未定义变量:事务(查看:/home/u305199682/public_html/dash/protected/app/views/pages/template/home.blade.php

$this->layout->nest('content',$page)
    ->with(array(
        'menus' => $this->menus,
        'transactions' => $transaction
    )
);

【问题讨论】:

【参考方案1】:

如果您想将数据传递给嵌套视图,请尝试

$this->layout->nest('content', $page, array(
    'menus' => $this->menus,
    'transactions' => $transaction
));

【讨论】:

【参考方案2】:

您需要为每个变量调用 with

$this
    ->layout
    ->nest('content',$page)
    ->with('menus',$this->menus)
    ->with("transactions",$transaction);

或将两个变量放入 1 个数组中。

$passVar = array(
                 'menus' => $this->menus,
                 'transaction' => $transaction
                );

$this
    ->layout
    ->nest('content',$page, $passVar);

【讨论】:

->with() 也接受数组,而不仅仅是(string, array)

以上是关于尝试将多个变量分配给刀片模板的主要内容,如果未能解决你的问题,请参考以下文章