English spoken conference

Extending the Page class

1.3 version
Maintained Unmaintained

Extending the Page classΒΆ

The default Page document (Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page) is relatively simple, shipping with a handful of the most common properties for building a typical page: title, body, tags, publish dates etc.

If this is not enough for your project you can easily provide your own document by extending the default Page document and explicitly setting the configuration parameter to your own document class:

  • YAML
    1
    2
    3
    4
    cmf_simple_cms:
        persistence:
            phpcr:
                document_class: Acme\DemoBundle\Document\MySuperPage
    
  • XML
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    <?xml version="1.0" charset="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services">
    
        <config xmlns="http://cmf.symfony.com/schema/dic/simplecms">
            <persistence>
                <phpcr
                    document-class="Acme\DemoBundle\Document\MySuperPage"
                />
            </persistence>
        </config>
    
    </container>
    
  • PHP
    1
    2
    3
    4
    5
    6
    7
    $container->loadFromExtension('cmf_simple_cms', array(
        'persistence' => array(
            'phpcr' => array(
                'document_class' => 'Acme\DemoBundle\Document\MySuperPage',
            ),
        ),
    ));
    

Alternatively, the default Page document contains an extras property. This is a key - value store (where value must be string or null) which can be used for small trivial additions, without having to extend the default Page document.

For example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page;
// ...

$page = new Page();

$page->setTitle('Hello World!');
$page->setBody('Really interesting stuff...');
$page->setLabel('Hello World');

// set extras
$extras = array(
    'subtext' => 'Add CMS functionality to applications built with the Symfony2 PHP framework.',
    'headline-icon' => 'exclamation.png',
);

$page->setExtras($extras);

$documentManager->persist($page);

These properties can then be accessed in your controller or templates via the getExtras() or getExtra($key) methods.

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