English spoken conference

Symfony 5: The Fast Track

A new book to learn about developing modern Symfony 5 applications.

Support this project

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

Installing and Configuring the CMF Core

1.0 version
Maintained Unmaintained

Installing and Configuring the CMF Core

Caution

The cookbook is in the process of being restructured. Some documentation is outdated, notable configuration examples. If something does not work, please have a look in the Reference section and send pull requests to fix things, or just open an issue on github so that we know about the problem.

Refer to the documentation issues to help us bringing this article up to date.

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
5
"minimum-stability": "dev",
"require": {
    ...
    "symfony-cmf/symfony-cmf": "1.0.*"
}

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
// 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\BlockBundle\SonataBlockBundle(),
    );

    // ...
}

Note

This also enables the PHPCR-ODM and related dependencies; setup instructions can be found in the dedicated documentation.

Configuration

To get your application running, very little configuration is needed.

Minimum Configuration

These steps are needed to ensure your AppKernel still runs.

If you haven't done so already, make sure you have followed these steps from Installing and Configuring Doctrine PHPCR-ODM:

  • Initialize DoctrinePHPCRBundle in app/AppKernel.php
  • Ensure there is a doctrine_phpcr: section in app/config/config.yml
  • Add the AnnotationRegistry::registerFile line to app/autoload.php

Configure the BlockBundle in your config.yml:

  • YAML
    1
    2
    3
    # app/config/config.yml
    sonata_block:
        default_contexts: [cms]
    

Additional Configuration

Because most CMF components use the DynamicRouter from the RoutingBundle, which by default is not loaded, you will need to enable it as follows:

  • YAML
    1
    2
    3
    4
    5
    6
    7
    8
    # app/config/config.yml
    cmf_routing:
        chain:
            routers_by_id:
                cmf_routing.dynamic_router: 200
                router.default: 100
        dynamic:
            enabled: true
    

You might want to configure more on the dynamic router, i.e. to automatically choose controllers based on content. See RoutingBundle for details.

For now this is the only configuration we need. Mastering the configuration of the different bundles will be handled in further articles. If you're looking for the configuration of a specific bundle take a look at the corresponding bundles reference.

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