English spoken conference
WARNING: You are browsing the documentation for version 1.1 which is not maintained anymore. If some of your projects are still using this version, consider upgrading.

Installing and Configuring the CMF Core Bundles

1.1 version
Maintained Unmaintained

Installing and Configuring the CMF Core Bundles

The goal of this tutorial is to install the minimal CMF components ("core") with the minimum necessary configuration. From there, you can begin incorporating CMF functionality into your application as needed.

This tutorial is aimed at the experienced user who wants to learn more about the details of the Symfony CMF. If this is your first encounter with the Symfony CMF it would be a good idea to start with:

Installation

Download the Bundles

Add the following to your composer.json file:

1
2
3
4
"require": {
    ...
    "symfony-cmf/symfony-cmf": "1.1.*"
}

And then run:

1
$ php composer.phar update

Initialize bundles

Next, initialize the bundles in AppKernel.php by adding them to the registerBundles method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// app/AppKernel.php

// ...
public function registerBundles()
{
    $bundles = array(
        // ...

        new Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle(),
        new Symfony\Cmf\Bundle\CoreBundle\CmfCoreBundle(),
        new Symfony\Cmf\Bundle\MenuBundle\CmfMenuBundle(),
        new Symfony\Cmf\Bundle\ContentBundle\CmfContentBundle(),
        new Symfony\Cmf\Bundle\BlockBundle\CmfBlockBundle(),

        // Dependencies of the CmfMenuBundle
        new Knp\Bundle\MenuBundle\KnpMenuBundle(),

        // Dependencies of the CmfBlockBundle
        new Sonata\CoreBundle\SonataCoreBundle(),
        new Sonata\BlockBundle\SonataBlockBundle(),
    );

    // ...
}

Configuration

To get your application running, very little configuration is needed. If you want to render menus from Twig, you need to enable this feature in the KnpMenuBundle:

  • YAML
    1
    2
    3
    # app/config/config.yml
    knp_menu:
        twig: true
    
  • XML
    1
    2
    3
    4
    5
    <!-- app/config/config.xml -->
    <?xml version="1.0" encoding="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services">
        <config xmlns="http://knplabs.com/schema/dic/menu" twig="true"/>
    </container>
    
  • PHP
    1
    2
    3
    4
    // app/config/config.php
    $container->loadFromExtension('knp_menu', array(
        'twig' => true,
    ));
    

Caution

While the CMF bundles work out of the box without configuration, you will need to configure a storage layer. To use the default provided model classes, you need PHPCR-ODM as well. Setup instructions are in DoctrinePHPCRBundle.

When using PHPCR-ODM, enable support globally for all CMF bundles with:

  • YAML
    1
    2
    3
    4
    5
    # app/config/config.yml
    cmf_core:
        persistence:
            phpcr:
                enabled: true
    
  • XML
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <!-- app/config/config.xml -->
    <?xml version="1.0" encoding="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services">
        <config xmlns="http://cmf.symfony.com/schema/dic/core">
            <persistence>
                <phpcr enabled="true"/>
            </persistence>
        </config>
    </container>
    
  • PHP
    1
    2
    3
    4
    5
    6
    7
    8
    // app/config/config.php
    $container->loadFromExtension('cmf_core', array(
        'persistence' => array(
            'phpcr' => array(
                'enabled' => true,
            ),
        ),
    ));
    

Next Steps

If you want to support multiple languages, have a look at Handling Multi-Language Documents.

Then have a look at the individual bundles you are interested in, and find the details on the configuration in the bundles configuration reference.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.