donglin5770 2015-02-11 10:56
浏览 24
已采纳

在CMS中选择页面视图/布局

I am building a CMS and my goal is to allow administrator to choose page view / layout ( Fullwidth, Sidebar, etc. )

So my question is what is the best practice to do this...

I am thinking create in database Layouts with ID and layout_name, and then in controller return View::make('$layout_name');

  • 写回答

2条回答 默认 最新

  • douyan6742 2015-02-11 11:16
    关注

    There are probably different ways to achieve this. In my opinion it's better to keep the make method non-dynamic and to share the layout setup across all the views with View:share. After what you may need to do an if statement to specify how your layouts have to be used.

    $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
    

    And in the concerned views:

    @if ($layout == 'full_width')
       @extends('layout.fullwidth')
    @elseif ($layout == 'sidebar')
       @extends('layout.sidebar')
    @endif
    

    This solution assumes that you know the different types of layouts that can be used.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 我这模型写的不对吗?为什么lingo解出来的下面影子价格这一溜少一个变量
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波