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条)

报告相同问题?

悬赏问题

  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出
  • ¥30 关于PHP中POST获取数据的问题
  • ¥30 微信小程序请求失败,网页能正常带锁访问
  • ¥15 Python实现hog特征图可视化
  • ¥30 德飞莱51单片机实现C4炸弹
  • ¥50 CrossLink-LIF-MD6000 型 FPGA 的 CMOS 转 MIPI D-PHY IP 核功能使用异常
  • ¥15 proteus控制16x16LED点阵显示屏的设计