Skip to content

Instantly share code, notes, and snippets.

@ederrafo
Last active October 21, 2018 02:22
Show Gist options
  • Save ederrafo/8b793462142ebaddf40205e9946a3e46 to your computer and use it in GitHub Desktop.
Save ederrafo/8b793462142ebaddf40205e9946a3e46 to your computer and use it in GitHub Desktop.
Use in ubuntu 14.04 lts
-- Install all stack developr
$ sudo apt-get update && sudo apt-get -y install apache2 php5 php5-mcrypt php5-mysql php5-odbc php5-mcrypt && sudo a2enmod rewrite && sudo service apache2 restart && cd ~ && curl -sS https://getcomposer.org/installer | sudo php && sudo mv composer.phar /usr/local/bin/composer && composer -V
$ sudo apt-get -y install git && git config --global user.email "[email protected]" && git config --global user.name "eder rafo" && git config --global alias.st status && git config --global alias.cm commit && git config --global alias.co checkout && git config --global alias.br branch && git config core.filemode false
-- Create administrator in sf2.8 compatible
$ php --version
PHP 5.5.9-1ubuntu4.26 (cli) (built: Sep 17 2018 13:46:30)
-- Install
$ composer create-project symfony/framework-standard-edition administrator "2.8"
-- Create virtualhost
# Virtualhost for application symfony2
<Directory "/vagrant_data">
Order allow,deny
Allow from all
# New directive needed in Apache 2.4.3:
Require all granted
AllowOverride All
</Directory>
<VirtualHost *:80>
ServerName symfony2-project.local
ServerAlias www.symfony2-project.local
ServerAdmin webmaster@localhost
DocumentRoot /vagrant_data/sf2-administrator/web
DirectoryIndex app.php
<Directory "/vagrant_data/sf2-administrator/web">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error-symfony2-project.local.log
CustomLog ${APACHE_LOG_DIR}/access-symfony2-project.local.log combined
</VirtualHost>
-- Sonata Admin bundle, installation
$ composer require sonata-project/admin-bundle "2.3.*"
-- In Vagrant VM always ocurred error of memmory lack swap, executed this command tha solved
$ sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=2048 && sudo /sbin/mkswap /var/swap.1 && sudo /sbin/swapon /var/swap.1
-- Installation storage bundles to be able to communicate with a database
$ composer require sonata-project/doctrine-orm-admin-bundle "2.3.*"
-- List all installed package
$ composer show -i
-- List installed dependences
$ composer show -i -t
-- Configure the Installed Bundles
# app/config/config.yml
sonata_block:
default_contexts: [cms]
blocks:
# enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
# ...
$ php app/console cache:clear && php app/console assets:install
-- Step 5 Import routing configuration
# app/config/routing.yml
admin_area:
resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /admin
-- Set styles
$ composer require jms/serializer-bundle ^1.1
-- Preparing your enviroment
$ php app/console cache:clear
$ php app/console assets:install
src : https://symfony.com/doc/2.x/bundles/SonataAdminBundle/getting_started/installation.html
2. Creating an Admin
2.1. Step 0: Create a Model
$ php app/console doctrine:generate:entity --entity="AppBundle:Category" --fields="name:string(255)" --no-interaction
$ php app/console doctrine:generate:entity --entity="AppBundle:BlogPost" --fields="title:string(255) body:text draft:boolean" --no-interaction
2.2. Step 1: Create an Admin Class
Create an Admin class for the Category entity. The easiest way to do this is by extending Sonata\AdminBundle\Admin\Admin
- Manage your data using a graphical interface that will let you create, update or search your model instances.
// src/AppBundle/Admin/CategoryAdmin.php
2.3. Step 2: Register the Admin class
You've now created an Admin class, but there is currently no way for the SonataAdminBundle to know that this Admin class exists. To tell the SonataAdminBundle of the existence of this Admin class, you have to create a service and tag it with the sonata.admin tag:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment