[英]How to push the values to blade template in Laravel 4
I am trying to push an array to the blade template in laravel 4 Controller name: AdminController 我试图在laravel 4控制器名称中将数组推送到刀片模板:AdminController
public function listCompanies()
{
$companyObj = new company();
$companies = $companyObj->getCompanies();
$this->layout->content = View::make('admin/main',$companies);
}
Template name: main.blade.php 模板名称:main.blade.php
<div class="container">
@yield('content')
@foreach ($companies as $company)
<p>This is company {{ $company['name'] }}</p>
@endforeach
</div>
The error I am getting is: Undefined variable: companies (View: C:\\wamp\\www\\larvel-project\\laravel\\app\\views\\admin\\main.blade.php) 我得到的错误是:未定义的变量:公司(视图:C:\\ wamp \\ www \\ larvel-project \\ laravel \\ app \\ views \\ admin \\ main.blade.php)
The view is expecting to receive an associative array which includes the index 'companies' and will turn that into $companies. 该视图期望接收一个包含索引“ companies”的关联数组,并将其转换为$ companies。
Any of the following should work for you: 以下任何一项都可以为您工作:
$this->layout->content = View::make('admin/main', ['companies' => $companies]);
$this->layout->content = View::make('admin/main', compact('companies'));
$this->layout->content = View::make('admin/main')->with('companies', $companies);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.