fbeen / simplecmsbundle

为Symfony 3提供完整的CMS功能

安装: 51

依赖者: 0

建议者: 0

安全性: 0

星星: 0

关注者: 4

分支: 0

开放问题: 0

类型:symfony-bundle

V1.0.4 2016-11-17 14:54 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:21:45 UTC


README

安装

使用Composer下载必要的包

$ composer require fbeen/simplecmsbundle

然后将包添加到app/config/AppKernel.php文件中

            // ...

            // Sonata
            new Sonata\CoreBundle\SonataCoreBundle(),
            new Sonata\BlockBundle\SonataBlockBundle(),
            new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
            new Sonata\AdminBundle\SonataAdminBundle(),
            
            // Ivory CKEditor
            new Ivory\CKEditorBundle\IvoryCKEditorBundle(),

            // Knp Menu
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),

            // Doctrine behaviors
            new Knp\DoctrineBehaviors\Bundle\DoctrineBehaviorsBundle,

            // a2lix Translation
            new A2lix\AutoFormBundle\A2lixAutoFormBundle(),
            new A2lix\TranslationFormBundle\A2lixTranslationFormBundle(),

            // Fbeen Simple CMS bundle
            new Fbeen\SimpleCmsBundle\FbeenSimpleCmsBundle(),
            
            new AppBundle\AppBundle(),

app/config/config.yml中所需的配置

sonata_block:
    default_contexts: [admin]
    blocks:
        # enable the SonataAdminBundle block
        sonata.admin.block.admin_list: ~
        sonata.block.service.clear_cache: ~

sonata_admin:
    show_mosaic_button: false
    dashboard:
        groups:
            cms:
                label: 'SimpleCMS'
                items:
                    - fbeen_simple_cms.admin.route
                    - fbeen_simple_cms.admin.content
                    - fbeen_simple_cms.admin.menu
                    - fbeen_simple_cms.admin.image
                    - fbeen_simple_cms.admin.simple_block_type
        blocks:
            -
                position: left
                type: sonata.admin.block.admin_list
                settings:
                    groups: [main, docs, users, cms]
            -
                position: left
                type: sonata.block.service.clear_cache

ivory_ck_editor:
    default_config: cmf_content
    configs:
        cmf_content: { toolbar: standard }

a2lix_translation_form:
    locale_provider: default
    locales: [%locale%]
    default_locale: %locale%
    required_locales: [%locale%]
    templating: "FbeenSimpleCmsBundle:Admin:a2lix_tabs.html.twig"

在app/config/config.yml中启用翻译

framework:
    #esi:             ~
    translator:      { fallbacks: ["%locale%"] }

创建数据库并更新架构

$ bin/console doctrine:database:create
$ bin/console doctrine:schema:update --force

在app/config/routing.yml中应用路由

# Simple CMS
fbeen_simple_cms:
    resource: .
    type: fbeen_simple_cms
    
# Sonata-admin
admin_area:
    resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
    prefix: /admin
    
_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /admin

# Application
app:
    resource: "@AppBundle/Controller/"
    type:     annotation
# ...

安装资源:(在Windows上不要使用符号链接选项)

$ bin/console assets:install --symlink

用法

如何在普通Symfony控制器中加载内容

加载动态内容就像从其他实体加载数据一样简单。要基于名称搜索内容,我们可以使用ContentRepository中的findCompleteContent方法。存储库将一次性连接所有其他数据,如blockContainer和基础块。

如何使用CMS内容和一些新闻条目创建主页的示例

    /**
     * @Route("/", name="homepage")
     */
    public function indexAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        
        $homepage = $em->getRepository('FbeenSimpleCmsBundle:Content')->findCompleteContent('homepage');

        if (!$homepage) {
            throw $this->createNotFoundException('No homepage configured');
        }

        $newsitems = $em->getRepository('AppBundle:Newsitem')->findFrontpageNews()->getResult();

        return $this->render('default/index.html.twig', array(
            'content' => $homepage,
            'newsitems' => $newsitems,
        ));
    }

多语言

想象一下,你想创建一个支持三种语言的网站,你希望荷兰语作为默认语言,英语和德语作为附加语言。

在参数下添加locales参数

parameters:
    locale: nl
    locales: [nl, en, de]

更改a2lix翻译表单配置

a2lix_translation_form:
    locale_provider: default
    locales: %locales%
    # ...

待续