【发布时间】:2016-04-13 05:39:21
【问题描述】:
在 Laravel 中,控制器中的每个方法都将包含 $heading['panelText']
例如:
public function pageName1()
{
$heading['panelText'][] = "Content Here one";
$heading['panelText'][] = "Content Here Two";
$heading['panelText'][] = "Content Here Three";
return View('mockup/pagename1', compact('heading'));
}
public function pageName2()
{
$heading['panelText'][] = "Some Random one";
$heading['panelText'][] = "Some Random Line Two";
return View('mockup/pagename2', compact('heading'));
}
在刀片文件中,它看起来像这样
@foreach($heading['panelText'] as $content)
<p>{{$content}}</p>
@endforeach
如您所见,控制器方法可能会有些混乱。我正在寻找一种更清洁的解决方案,我不必在控制器方法中定义 $heading['panelText'] 的值?也许创建一个库以包含 $heading 内容列表,并且控制器将使用该库或者我该怎么做?
【问题讨论】:
标签: php laravel laravel-4 laravel-blade