Version

Documentation » News

3. Advanced Configuration »

« 1. Introduction

2. Installation

  • Add SonataNewsBundle to your vendor/bundles dir with the deps file:
  • Add SonataNewsBundle to your application kernel:
// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Sonata\NewsBundle\SonataNewsBundle(),
        new Sonata\UserBundle\SonataUserBundle(),
        new Sonata\MediaBundle\SonataMediaBundle(),
        new Sonata\AdminBundle\SonataAdminBundle(),
        new Sonata\IntlBundle\SonataIntlBundle(),
        new Sonata\FormatterBundle\SonataFormatterBundle(),
        new FOS\UserBundle\FOSUserBundle(),
        new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
        new Knp\Bundle\MenuBundle\KnpMenuBundle(),
        // ...
    );
}
  • Update the autoload.php to add a new namespace:
<?php
$loader->registerNamespaces(array(
    'Sonata'        => __DIR__,
    'Application'   => __DIR__,
    'FOS'           => __DIR__.'/../vendor/bundles',
    'Knp'           => array(
        __DIR__.'/../vendor/bundles',
        __DIR__.'/../vendor/knp/menu/src'
    ),
    // ... other declarations
));
  • Run the easy-extends command:

    php app/console sonata:easy-extends:generate SonataNewsBundle
    php app/console sonata:easy-extends:generate SonataUserBundle
    php app/console sonata:easy-extends:generate SonataMediaBundle
    
  • Enable the new bundles:

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Application\Sonata\NewsBundle\ApplicationSonataNewsBundle(),
        new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
        new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(),
        // ...
    );
}
  • Complete the FOS/UserBundle install and use the Application\Sonata\UserBundle\Entity\User as the user class
  • Add SonataNewsBundle routes to your application routing.yml:
# app/config/routing.yml
news:
    resource: '@SonataNewsBundle/Resources/config/routing/news.xml'
    prefix: /news
  • Add a configuration file : sonata_news.yml:
sonata_news:
    title:        Sonata Project
    link:         http://sonata-project.org
    description:  Cool bundles on top of Symfony2
    salt:         'secureToken'
    permalink_generator: sonata.news.permalink.date # sonata.news.permalink.category

    comment:
        notification:
            emails:   [[email protected], [email protected]]
            from:     [email protected]
            template: 'SonataNewsBundle:Mail:comment_notification.txt.twig'

doctrine:
    orm:
        entity_managers:
            default:
                #metadata_cache_driver: apc
                #query_cache_driver: apc
                #result_cache_driver: apc
                mappings:
                    ApplicationSonataNewsBundle: ~
                    SonataNewsBundle: ~
  • import the sonata_news.yml file:
imports:
    - { resource: sonata_news.yml }
  • Add a new context into your sonata_media.yml configuration:
news:
    providers:
        - sonata.media.provider.dailymotion
        - sonata.media.provider.youtube
        - sonata.media.provider.image

    formats:
        small: { width: 150 , quality: 95}
        big:   { width: 500 , quality: 90}
  • Define the text formatters available for your blog post:
sonata_formatter:
    formatters:
        markdown:
            service: sonata.formatter.text.markdown
            extensions:
                - sonata.formatter.twig.control_flow
                - sonata.formatter.twig.gist
                - sonata.media.formatter.twig

Found a typo? Something is wrong in this documentation? Just fork and edit it!