dpb_4431 2019-01-12 17:43
浏览 72
已采纳

这是在laravel中构建模板/布局系统的好方法吗? 将数据保存到数据库会更好吗?

I'm building a Laravel PHP application where a user will be able to create 'layouts' for pages.

To make a layout a user enters HTML in a form and optionally they may specify areas where, when creating a page that uses this layout, a WYSIWYG editor would allow an editor to add content.

What happens now is this HTML is saved in /storage/templates/layouts as a .blade.php file. The user designates the editable areas by using blade's @yield directive. Each editable area is wrapped with an @section directive and concatenated into a single .blade.php file and the @extends() directive is added, referencing the layout. Then it's saved in /storage/templates/pages. When a page is requested, it simply returns the view as a normal blade view return view('templates.pages.{page_slug}');.

In terms of performance, security and maintainability is this a good approach? Would storing this data in a database be better? Any suggestions for improving?

  • 写回答

1条回答 默认 最新

  • douxunwei8259 2019-01-12 18:41
    关注

    I think this is not good for security purposes. If I understand correctly, the user can enter blade code? Or html code which is stored in blade files? If so, they can execute PHP code on your server. For example, if I would write in my html file:

    @php(\App\User::first()->some_data)
    

    I could get all user data, delete all files and can basically control everything. I would probably store only the HTML in normal files or in the database and load them with: {!! $userPage->htmlCode !!} or something. So they can enter html code but not PHP / Blade code.

    If you have any questions, feel free to comment!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?