我正在构建一个 CMS,我的目标是允许管理员选择页面 View /布局(全宽、侧边栏等)
所以我的问题是执行此操作的最佳实践是什么......
我正在考虑使用ID和layout_name在数据库布局中创建,然后在 Controller 中return View::make('$layout_name');
最佳答案
可能有不同的方法可以实现这一目标。
在我看来,最好保持 make
方法为非动态,并使用 View:share
在所有 View 之间共享布局设置。
之后,您可能需要执行 if 语句来指定如何使用布局。
$layout_name = 'full_width'; // should be the result of the db query
View:share('layout', $layout_name); // use it in your controllers, wherever you want
在相关观点中:
@if ($layout == 'full_width')
@extends('layout.fullwidth')
@elseif ($layout == 'sidebar')
@extends('layout.sidebar')
@endif
此解决方案假设您知道可以使用的不同类型的布局。
关于php - 在 CMS 中选择页面 View /布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28452584/