【问题标题】: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
    )
);

【问题讨论】:

    标签: php laravel laravel-4 blade


    【解决方案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)
      猜你喜欢
      • 2018-01-13
      • 1970-01-01
      • 2014-12-08
      • 2017-09-07
      • 1970-01-01
      • 1970-01-01
      • 2018-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多