12 articles Symfony 2

Install Symfony 2.6

Symfony Install Composer: First of all, these commands install composer on your system: curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer Install Symfony: Create your project # composer create-project symfony/framework-standard-edition /path/to/webroot/Symfony ‘2.6.*’ Set folders rights Go in your /path/to/webroot/symfony directory # chmod -R 777 app/cache # chmod -R 777 app/logs Create an Admin Bundle :…

Install Sonata

Install Sonata Note To speed up the installation, all composer are used with –no update option. composer update is only used at the end of the installation to get all bundles in once. Get Sonata Make sure composer is updated # sudo /usr/local/bin/composer self-update Get Sonata Bundle # composer require sonata-project/admin-bundle –no-update Get ORM Bundle # composer require…

Sonata – Install UserBundle

Install Sonata user Installation Install FOS # composer require friendsofsymfony/user-bundle –no-update Enable the bundle # composer require sonata-project/user-bundle –no-update # composer require sonata-project/doctrine-orm-admin-bundle –no-update # optional # composer update Then add in app/AppKernel.php <?php // app/AppKernel.php public function registerbundles() { return array( // … // extend the “FOSUserBundle“ new FOS\UserBundle\FOSUserBundle(), new Sonata\UserBundle\SonataUserBundle(‘FOSUserBundle’), ); } Enable preventing…

Sonata – Install MediaBundle

Composer install Installation Execute: composer require sonata-project/media-bundle –no-update composer require jms/serializer-bundle –no-update composer require sonata-project/intl-bundle –no-update composer update Add in app/AppKernel.php # app/AppKernel.php public function registerBundles() {     $bundles = array( /…/ // MediaBundle         new Sonata\MediaBundle\SonataMediaBundle(),         new JMS\SerializerBundle\JMSSerializerBundle(),         new Sonata\IntlBundle\SonataIntlBundle(), /…/ }…

Sonata – MediaBundle Image Resizer

Sonata MediaBundle comes with two type of resizer: sonata.media.resizer.simple and sonata.media.resizer.square. To make a custom resizer which will always keeps the same defined width and height, you need to create your own custom resizer. Step 1: create a service First you have to create a resizer service in order to call it: # app/config/services.yml services:…

Symfony – Create a Soap server with Zend Soap

In this example we will create an ApiBundle and a Soap server. Then a simple web service that return the name you send. Install Zend Framework Vendor To install Zend Framework vendor, execute # composer require zendframework/zend-soap Create ApiBundle To create the ApiBundle, execute # php app/console generate:bundle –namespace=Acme/ApiBundle –format=yml Add routing in app/config/routing.yml # app/config/routing.yml acme_api:…

Symfony – Create a post Form with a Rest server

Notes We will assume that ApiBundle have been generated with : # php app/console generate:bundle –namespace=Acme/ApiBundle –format=yml Composer intall composer require “friendsofsymfony/rest-bundle” –no-update composer require “jms/serializer-bundle” –no-update composer require “nelmio/api-doc-bundle” –no-update composer update Configuration Edit AppKernel Add in app/AppKernel.php <?php // app/AppKernel.php public function registerbundles() { return array( // … new FOS\RestBundle\FOSRestBundle(), new JMS\SerializerBundle\JMSSerializerBundle(), new…

Symfony – persistant translate with FOSUserBundle

This page is about setting a choice between different languages for anonymous users, and make it persistant during navigation. And how to set the language defined by a FOS User. Use JMSI18nRoutingBundle Usage JMSI18nRoutingBundle is a good bundle for translation. It can generate dictionaries from Controllers and from routing. Go to the JMSI18nRoutingBundle website for more…

Sonata – miscellaneous configuration

Change Sonata Admin bottom sidebar link To change the Sonata Admin bottom sidebar link, you need to: Create the file src/Acme/AdminBundle/standard_layout.html.twig Add : {% extends ‘SonataAdminBundle::standard_layout.html.twig’ %} {% block side_bar_after_nav %} your custom link here {% endblock %} Then add in app/config/config.yml: sonata_admin: // … templates: layout: CanalAdminBundle::standard_layout.html.twig Sonata Admin Remember me To make remember…