【发布时间】:2012-11-10 05:10:10
【问题描述】:
我用谷歌搜索了两个小时,但没有找到答案。也许你可以帮忙。
当我在 MyController 中定义时:
class MyController extends Base_Controller {
public $layout = 'layouts.default';
public function get_index() {
$entries = Entry::all();
return View::make('entries.index')
->with('entries', $entries);
}
}
}
在entries\index.blade.php:
@section('content')
<h1>Test</h1>
@endsection
在layouts\default.blade.php中:
<!DOCTYPE html>
<html>
<body>
@yield('content')
</body>
</html>
什么都没有显示。我不明白为什么。当我在 MyController 中替换时,返回部分:
$this->layout->nest('content', 'entries.index', array(
'entries' => $entries
));
然后一切正常,但是.. 它看起来不干净,我不喜欢它。在每个视图中添加 @layout('layouts.default') 时,一切都运行良好,但它不是 DRY。例如,在 RoR 中,我不需要在 Controller 中做这些事情。
如何在MyController 中定义一个布局并使用return View::make(我认为这是正确的方式)或者如何做得更好?
【问题讨论】: