项目作者: sokil

项目描述 :
Backend for static page management
高级语言: PHP
项目地址: git://github.com/sokil/StaticPageBundle.git
创建时间: 2016-08-03T18:31:01Z
项目社区:https://github.com/sokil/StaticPageBundle

开源协议:MIT License

下载


StaticPageBundle

Installation

Install bundle through composer:

  1. composer.phar require sokil/static-page-bundle

Add bundle to AppKernel:

  1. <?php
  2. class AppKernel extends Kernel
  3. {
  4. public function registerBundles()
  5. {
  6. $bundles = array(
  7. new Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle(),
  8. new Sokil\StaticPageBundle\StaticPageBundle(),
  9. );
  10. }
  11. }

Configuration

Page view

Place file to app/Resources/StaticPageBundle/views/Page/index.html.twig with your own markup of static page.
Page instance Sokil\StaticPageBundle\Entity\Page accessable as page variable, also locale must be passed to template. To get localized data, call page.getLocalizations()[locale] which gives you instance of Sokil\StaticPageBundle\Entity\PageLocalization.

Routing

To enable default routing configuration just add routing.yml to you routes config app/config/routing.yml:

  1. static_page:
  2. resource: "@StaticPageBundle/Resources/config/routing.yml"
  3. prefix: /

Or add your own routes for required actions.

To route any unexisted url to static page handler, you need to add some configuration to app/config/config.yml:

  1. cmf_routing:
  2. chain:
  3. routers_by_id:
  4. router.default: 200
  5. static_page.page_router: 100
  6. dynamic:
  7. persistence:
  8. orm:
  9. enabled: true

Roles

Register role at app/config/security.yml:

  1. # http://symfony.com/doc/current/book/security.html
  2. security:
  3. encoders:
  4. FOS\UserBundle\Model\UserInterface: sha512
  5. # http://symfony.com/doc/current/book/security.html#hierarchical-roles
  6. role_hierarchy:
  7. ROLE_PAGE_MANAGER: [ROLE_USER]

SPA view

Bundle has some SPA routes and dependencie for managing static pages, so you can configure them,
for example with sokil/frontend-bundle:

  1. {% import "@FrontendBundle/Resources/views/macro.html.twig" as frontend %}
  2. {% import "@StaticPageBundle/Resources/views/macro.html.twig" as staticPageSpa %}
  3. {{ staticPageSpa.jsResources() }}
  4. <script type="text/javascript">
  5. (function() {
  6. // app options
  7. var options = {{ applicationData|json_encode|raw }};
  8. // router
  9. options.routers = [
  10. StaticPageRouter
  11. ];
  12. // requirejs
  13. options.requireJs = [
  14. StaticPageRequireJsConfig
  15. ];
  16. window.app = new Application(options);
  17. window.app.start();
  18. })();
  19. </script>

Deploy

If you want to use embedded editor, you need to setup SPA.

You need to execute grunt tasks to build SPA:

  1. npm install
  2. bower install
  3. grunt

Bundle uses assetic bundle, so you need to register it in assetic config:

  1. assetic:
  2. bundles:
  3. - StaticPageBundle