2013-01-24 3 views
1

Laravel 4에서 마스터 레이아웃에 변수를 보내는 방법은 무엇입니까? 여기Laravel 4에서 마스터 레이아웃에 변수를 보내는 방법은 무엇입니까?

$ 범주는 마스터 레이아웃에서 사용할 수 없습니다 :

protected $layout = 'layouts.master'; 

public function index() 
{ 
    $categories = Category::all(); 
    $data = array('categories' => $categories); 
    $this->layout->content = View::make('catalog.categories', $data); 
} 

내 마스터보기 :

@yield('content') 

@if($categories) 
    <h1>TEST</h1> 
@endif 

"TEST"표시되지 않습니다!

+0

100 % 확인, Laravel 4.2로, 여기에서 내가 작업 있어요 방법 코멘트로 :'$ this-> layout-> with ($ data)'를 시도 했습니까? – Franz

답변

5

나는 당신이 사용할 수 있다고 생각 :

$this->layout->with('catalog.categories', $data); 
+0

괜찮습니까, 작동합니까. 고맙습니다 :) – EpokK

0

그 많은 laravel 함께 일하지 않은,하지만 난 네 생각 : 마스터에 그런

@extends('layout/master') 

// define what will be send to the master: 
@section('cats') 
    {{ $categories }} 
@stop 

: 당신의 child 템플릿에서

View::make('catalog.categories', $data); // this looks correct 

, 마스터 레이아웃을 확장해야 :

@yield('cats') 
2

$ 카테고리에 어떤 데이터라도?

당신이 시도 할 수 있습니다 :

View::make('catalog.categories')->with('categories', $categories); 
0

나는 너무이 문제가 발생했습니다.

레이아웃에 데이터를 전달하려면 : 귀하의 경우

$this->layout->content = View::share('data', $data); 

, 여기 방법은 다음과 같습니다 그래서 추가

protected $layout = 'layouts.master'; 

public function index() 
{ 
    $categories = Category::all(); 
    $data = array('categories' => $categories); 
    $this->layout->content = View::share('data', $data); 
    $this->layout->content = View::make('catalog.categories', $data); 
}