spyrit/page-builder-bundle
Composer 安装命令:
composer require spyrit/page-builder-bundle
包简介
A page builder for Symfony and Doctrine.
README 文档
README
About
A page builder to integrate in a Symfony/Doctrine/Twig project.
Notice: this bundle is highly experimental, there may be important changes without warning.
Basic principles
A page is a set of lines which contain zones (think about the Bootstrap grid with rows and divs that cover columns).
Each zone can contain one or several blocks. A block is an instantiation of a widget. Widgets are a set of configurable elements.
A few widgets (button, image, horizontal line, text) are provided but you will need to implement your own based on the purpose of your application (custom videos, articles, etc.).
Installation
Require the bundle with composer:
composer require spyrit/page-builder-bundle
Storage
Ideally, we would like this bundle to be storage-agnostic.
For now, it has only been used with Doctrine, so you are encouraged to set up database, and the following entities Block, Page, Zone.
You can name those entities as you like. You can create specific entities or reuse ones from your project. You can make them use BlockTrait, PageTrait and ZoneTrait but you don't have to. But your entities must extend BlockInterface, PageInterface, ZoneInterface.
<?php
namespace App\Entity;
use App\Repository\BlocRepository;
use Doctrine\ORM\Mapping as ORM;
use Spyrit\Bundle\SpyritPageBuilderBundle\Model\BlockInterface;
use Spyrit\Bundle\SpyritPageBuilderBundle\Model\BlockTrait;
/**
* @ORM\Entity(repositoryClass=BlockRepository::class)
*/
class Block implements BlockInterface
{
use BlockTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
public function getId(): ?int
{
return $this->id;
}
}
You will have to implement the getConfiguration, setConfiguration and getWidget methods in your class to match your storage.
If you add custom widgets, you will also need to implement setWidget.
<?php
namespace App\Entity;
use App\Repository\PageRepository;
use Doctrine\ORM\Mapping as ORM;
use Spyrit\Bundle\SpyritPageBuilderBundle\Model\PageInterface;
use Spyrit\Bundle\SpyritPageBuilderBundle\Model\PageTrait;
/**
* @ORM\Entity(repositoryClass=PageRepository::class)
*/
class Page implements PageInterface
{
use PageTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
public function getId(): ?int
{
return $this->id;
}
}
<?php
namespace App\Entity;
use App\Repository\ZoneRepository;
use Doctrine\ORM\Mapping as ORM;
use Spyrit\Bundle\SpyritPageBuilderBundle\Model\ZoneInterface;
use Spyrit\Bundle\SpyritPageBuilderBundle\Model\ZoneTrait;
/**
* @ORM\Entity(repositoryClass=ZoneRepository::class)
*/
class Zone implements ZoneInterface
{
use ZoneTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
public function getId(): ?int
{
return $this->id;
}
}
How to use
Add a widget
- Create a class that heritates from BaseWidget.
- Create Twig templates for your widget (one editor template and one front template if needed)
- Create your widget's form
Render (read only)
- To display a build page (e.g. on a public route), you will need to call the
renderPagemethod from theRenderManagerservice.
use Spyrit\Bundle\SpyritPageBuilderBundle\Manager\RenderManager;
public function show(Page $page, RenderManager $renderManager): Response
{
return $this->render('render.html.twig', [
'html' => $renderManager->renderPage($page),
]);
}
Where render.html.twig can mimic @SpyritPageBuilder/render/base.html.twig.
Render (editor)
- To render the page builder (e.g. on a private route, for admins), you will need to call the
renderPagemethod from theRenderManagerservice, with the second argument astrue.
use Spyrit\Bundle\SpyritPageBuilderBundle\Manager\RenderManager;
use Spyrit\Bundle\SpyritPageBuilderBundle\Widget\Widget;
public function edit(Page $page, RenderManager $renderManager): Response
return $this->render('editor.html.twig', [
'html' => $renderManager->renderPage($page, true),
'widgets' => Widget::CHOICES, // or plug here your custom list of Widgets
]);
}
Where editor.html.twig can mimic @SpyritPageBuilder/editor/editor.html.twig.
Styling the editor
You are encouraged to write your own CSS, but you can also use the provided page-builder.scss. To use it, add this to your webpack.config.js:
.addStyleEntry('css/page-builder', './vendor/spyrit/page-builder-bundle/src/Resources/public/css/page-builder.scss')
And in your editor page:
{% extends 'your_base_layout.html.twig' %}
{% block stylesheets %}
{{ encore_entry_link_tags('css/page-builder') }}
{% endblock %}
{% block body %}
<div class="page-editor">
{% include '@SpyritPageBuilder/editor/editor.html.twig' %}
</div>
{% endblock %}
{% block javascripts %}
{{ include('@SpyritPageBuilder/editor/editor_js.html.twig') }}
{% endblock %}
spyrit/page-builder-bundle 适用场景与选型建议
spyrit/page-builder-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.72k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2019 年 02 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「doctrine」 「page builder」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spyrit/page-builder-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spyrit/page-builder-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spyrit/page-builder-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
DataTables is a plug-in for the jQuery Javascript library. It is a highly flexible tool, based upon the foundations of progressive enhancement, which will add advanced interaction controls to any HTML table.
Plug-ins for DataTables
The bundle for easy using json-rpc api on your project
This package helps you use bitwise enums in PHP and Laravel.
Make pimcore migration simple
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 6.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-21
