php - 在 CMS 中选择页面 View /布局

标签 php mysql laravel laravel-4 laravel-5

我正在构建一个 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/

相关文章:

php - 存储表单值而不将其发送到 MySQL 数据库进行支付网关处理的最佳方法

php - laravel save() 方法是否抛出异常?

php - WordPress:禁用默认样式@load-styles.php

PHP三元运算符不解析类内部属性?

mysql - 大查询 : Join single latest row from second table

php - 无法在 Laravel 的 index.php 之外命中断点

javascript - JavaScript 中的 PHP 和转义

php - Laravel 规则和正则表达式 (OR) 运算符的问题

php - 如何修复 Symfony/Goutte 中的 SSL 问题

mysql - Mamp mysql-server 停止工作