spiral / pieces
此包已被废弃且不再维护。未建议替代包。
螺旋框架组件模块
v1.0.8
2017-08-08 12:30 UTC
Requires
- php: >=7.0
- ext-imagick: *
- oscarotero/psr7-middlewares: ^3.20
- spiral/auth: ^0.9
- spiral/framework: ^1.0.5
- spiral/storage: ^1.0
Requires (Dev)
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ~6.0
- symfony/dom-crawler: ^3.2
README
此模块提供在数据库(目前仅ORM)中存储页面组件数据并通过Web-API访问的能力。同时,它编译了两种视图版本:一个用于网站编辑器,一个用于普通网站用户。这种功能有时非常有用,特别是对于像 WriteAway 这样的东西。
安装
$ composer require spiral/pieces $ ./spiral register spiral/pieces $ ./spiral up
添加引导加载器
const LOAD = [ //... \Spiral\Pieces\Bootloaders\PiecesBootloaders::class, ]
配置权限
详细信息请检查 app/config/modules/pieces.php
。
元数据
将元数据包含到页面中有两种选择:“静态”和“运行时”。第一种将在视图编译期间完全编译,在页面加载期间不会有数据库请求。第二种则不会。
<dark:use path="pieces/meta" as="pieces:meta"/> <pieces:meta title="Foo" description="Bar" keywords="Baz"> <meta name="foo" content="bar"> </pieces:meta>
上面的代码是“静态”元数据。您可以可选地传递一些默认值:title
、description
、keywords
参数,并放置自定义的默认HTML(见上面代码)。
如果您需要比简单的静态页面更复杂的东西,那么目前您需要使用“运行时”元数据。与“静态”元数据相反,您应该传递 namespace
、view
和 code
参数,但 title
、description
和 keywords
仍然是可选的。
<dark:use path="pieces/runtime-meta" as="pieces:meta"/> <?php #compile /** @var Article $entity */ ?> <pieces:meta title="<?= $entity->title ?>" description="<?= $entity->description ?>" namespace="<?= $this->namespace #compile ?>" view="<?= $this->view #compile ?>" code="<?= $entity->id ?>"> <meta name="foo" content="bar"> </pieces:meta>
值得注意的是,两种选择都会附加(在编辑模式下)
<script> window.metadata = <?= json_encode($meta) ?>; </script>
以帮助您设置前端编辑器。
如果您不喜欢这种行为,您总是可以编写自己的代码... 并提交一个PR。:-)
组件
目前只有“静态”组件。
<dark:use path="pieces/piece" as="pieces:piece"/> <pieces:piece name="sample-piece"> Piece content. </pieces:piece>
在编辑模式下,组件的内容将被包裹在div中,如下所示
<div data-piece="html" data-id="sample-piece"> Piece content. </div>