sokil / static-page-bundle
此包已被 弃用 且不再维护。未建议替代包。
静态页面管理器包
0.3
2016-10-17 18:34 UTC
Requires
- php: ^5.6 || ^7.0
Requires (Dev)
- phpunit/phpunit: 5.4.*
- satooshi/php-coveralls: 1.0.*
Suggests
- sokil/frontend-bundle: Frontend components to edit page
README
安装
使用 composer 安装包
composer.phar require sokil/static-page-bundle
将包添加到 AppKernel
<?php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( new Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle(), new Sokil\StaticPageBundle\StaticPageBundle(), ); } }
配置
页面视图
将文件放置于 app/Resources/StaticPageBundle/views/Page/index.html.twig,并添加自己的静态页面标记。页面实例 Sokil\StaticPageBundle\Entity\Page 可通过 page 变量访问,同时 locale 也必须传递给模板。要获取本地化数据,调用 page.getLocalizations()[locale],这将返回一个 Sokil\StaticPageBundle\Entity\PageLocalization 实例。
路由
要启用默认路由配置,只需将 routing.yml 添加到您的路由配置 app/config/routing.yml 中
static_page: resource: "@StaticPageBundle/Resources/config/routing.yml" prefix: /
或者添加您自己的路由以执行所需操作。
要将任何不存在的 URL 路由到静态页面处理器,您需要向 app/config/config.yml 中添加一些配置
cmf_routing: chain: routers_by_id: router.default: 200 static_page.page_router: 100 dynamic: persistence: orm: enabled: true
角色
在 app/config/security.yml 中注册角色
# https://symfony.com.cn/doc/current/book/security.html security: encoders: FOS\UserBundle\Model\UserInterface: sha512 # https://symfony.com.cn/doc/current/book/security.html#hierarchical-roles role_hierarchy: ROLE_PAGE_MANAGER: [ROLE_USER]
单页面应用视图
包包含一些用于管理静态页面的 SPA 路由和依赖项,因此您可以进行配置,例如使用 sokil/frontend-bundle
{% import "@FrontendBundle/Resources/views/macro.html.twig" as frontend %}
{% import "@StaticPageBundle/Resources/views/macro.html.twig" as staticPageSpa %}
{{ staticPageSpa.jsResources() }}
<script type="text/javascript">
(function() {
// app options
var options = {{ applicationData|json_encode|raw }};
// router
options.routers = [
StaticPageRouter
];
// requirejs
options.requireJs = [
StaticPageRequireJsConfig
];
window.app = new Application(options);
window.app.start();
})();
</script>
部署
如果您想使用嵌入式编辑器,您需要设置 SPA。
您需要执行 grunt 任务来构建 SPA
npm install
bower install
grunt
包使用 assetic 包,因此您需要将其注册在 assetic 配置中
assetic: bundles: - StaticPageBundle