Back-end with SonataAdminBundle (and Symfony2, of course...)

28
BACK-END WITH SONATA ADMIN BUNDLE AND SYMFONY2, OF COURSE... Andrea Delfino andrea.delfi[email protected] SYMFONYDAY 2012 sabato 6 ottobre 12

description

A brief overview on how build administration panels with SonataAdminBundle for Symfony2 php framework. (SymfonyDay Italia 2012 - 5 Oct 2012)

Transcript of Back-end with SonataAdminBundle (and Symfony2, of course...)

Page 1: Back-end with SonataAdminBundle (and Symfony2, of course...)

BACK-END WITH

SONATA ADMIN BUNDLEAND SYMFONY2, OF COURSE...

Andrea [email protected]

SYMFONYDAY 2012sabato 6 ottobre 12

Page 2: Back-end with SonataAdminBundle (and Symfony2, of course...)

SYMFONYDAY 2012

•Developer with 10+ years experience•Either SysAdmin (DevOps ❤)•Actually working for Skuola.net•I love Free Software (free as in freedom)•Knowledge sharing (Web, LUG, ..., PUG)

@ottimohttps://github.com/andreadelfino

PUG Turin: http://torino.grusp.org

sabato 6 ottobre 12

Page 3: Back-end with SonataAdminBundle (and Symfony2, of course...)

THE PROBLEMTIME

Often we have little time for developing the back-end

SYMFONYDAY 2012sabato 6 ottobre 12

Page 4: Back-end with SonataAdminBundle (and Symfony2, of course...)

EXPECTATIONSWe're migrating from an CMS with a good back-end

THE PROBLEM

SYMFONYDAY 2012sabato 6 ottobre 12

Page 5: Back-end with SonataAdminBundle (and Symfony2, of course...)

THE SOLUTION

phpMyAdmin

SYMFONYDAY 2012

Xsabato 6 ottobre 12

Page 6: Back-end with SonataAdminBundle (and Symfony2, of course...)

ALTERNATIVE

SYMFONYDAY 2012

• Homebrew• Altri Framework• SF2/Doctrine CRUD Generator• AdmingeneratorGeneratorBundle• WhiteOctoberAdminBundle• FooSimpleAdminBundle (one-dev-bundle)

sabato 6 ottobre 12

Page 7: Back-end with SonataAdminBundle (and Symfony2, of course...)

OR...

SonataAdminBundle

SYMFONYDAY 2012

“Admin is not only about Model; but about providing a consistent and rich user experience for managing data.”

Thomas Rabaix

sabato 6 ottobre 12

Page 8: Back-end with SonataAdminBundle (and Symfony2, of course...)

SONATA PROJECT

SYMFONYDAY 2012

• Mantainer : Thomas Rabaix (https://github.com/rande)

• Sponsor: Ekino (http://www.ekino.com)

• Obiettivo: e-commerce framework• State: 13 bundles e some libraries

http://sonata-project.org

sabato 6 ottobre 12

Page 9: Back-end with SonataAdminBundle (and Symfony2, of course...)

FEATURES OVERVIEW

SYMFONYDAY 2012

Dashboard

List•Automatic sort•Link to associated admin (Post => User)•Custom templates•Row Action: edit, create, view, ...•Batch Action•Clever row visualisation: boolean values are

represented with 'check picture'•Filter•Pagination

Edit / Create•Inline edition•Association management (create related model with

+ icon)•Group fields•Sortable option•Modal window to select model (when the list can be

important)•Dynamic form on [one|many]-to-many association

(add new element)

Templating•Base templates (field, list, filter) can be overwritten•Layout templates can be defined into the Service

Container

Others•Nested Admin (ie: /news/post/5/comment/list filter

and create comments only for the post with id=5)•Contextual Breadcrumb•Persistent parameters across an Admin•Side menu option•Translated into 17 languages: CA, DE, EN, ES, FR, HR,

IT, JA, LB, NL, PL, PT_BR, PT_PT, RU, SK, SL and UK•Built to be extended•Explain command line utility

Bundles (on top of)•SonataMediaBundle: a media manager bundle•SonataNewsBundle: a news/blog bundle•SonataPageBundle: a page (CMS like) bundle•SonataUserBundle: integration of FOSUserBundle and

SonataAdminBundle

sabato 6 ottobre 12

Page 10: Back-end with SonataAdminBundle (and Symfony2, of course...)

ECOSYSTEM

SYMFONYDAY 2012

SonataAdminBundleabstract class Admin

SonataDoctrineORMAdmin SonataDoctrineMongoDBAdmin SonataDoctrinePhpcrAdmin

Symfony FrameworkSymfony Components

SonataCacheBundleSonataBlockBundle

SonataJQueryBundleKnpMenuBundle

Exporter

SonataPageBundleSonataNewsBundleSonataMediaBundleSonataUserBundle

Symfony CMF

sabato 6 ottobre 12

Page 11: Back-end with SonataAdminBundle (and Symfony2, of course...)

INSTALLATION

SYMFONYDAY 2012

• vi deps && vendors install (branch/2.0 + sf2.0)• composer (master + sf2.1)

sabato 6 ottobre 12

Page 12: Back-end with SonataAdminBundle (and Symfony2, of course...)

CONFIGURATION

SYMFONYDAY 2012

• autoload.php + AppKernel.php• config.yml + routing.yml

sabato 6 ottobre 12

Page 13: Back-end with SonataAdminBundle (and Symfony2, of course...)

MAYBE NOT EVERYONE KNOWS THAT...

SYMFONYDAY 2012

In Bundle Standalone src/ Skuola/ UniversitaBundle/ Admin/ VersioniBundle/ Admin/ ...

src/ Skuola/ AdminBundle/ Admin/ UniversitaBundle/ VersioniBundle/ ...

skuola.net/admin admin.skuola.net

sabato 6 ottobre 12

Page 14: Back-end with SonataAdminBundle (and Symfony2, of course...)

ADMIN CLASS

SYMFONYDAY 2012

Class as a Service

Our Admin class

Admin pool Controller

Service

Dashboardgroup

Entity

sabato 6 ottobre 12

Page 15: Back-end with SonataAdminBundle (and Symfony2, of course...)

DASHBOARD

SYMFONYDAY 2012

} Group

Twitter Bootstrap ;)Quick actions

Entities

sabato 6 ottobre 12

Page 16: Back-end with SonataAdminBundle (and Symfony2, of course...)

LIST VIEW

SYMFONYDAY 2012

Filters

Custom fields Actions

Batch actions

Export

sabato 6 ottobre 12

Page 17: Back-end with SonataAdminBundle (and Symfony2, of course...)

LIST VIEW

SYMFONYDAY 2012sabato 6 ottobre 12

Page 18: Back-end with SonataAdminBundle (and Symfony2, of course...)

LIST VIEW

SYMFONYDAY 2012

Custom Template

Custom Actions

Admin class

List Mapper

sabato 6 ottobre 12

Page 19: Back-end with SonataAdminBundle (and Symfony2, of course...)

LIST VIEW

SYMFONYDAY 2012

Filters

Actions Route

sabato 6 ottobre 12

Page 20: Back-end with SonataAdminBundle (and Symfony2, of course...)

EDIT / CREATE FORM

SYMFONYDAY 2012

Associated Entity

CRUD Actions

Help inline

PropertiesEntity Collection

(ManyToMany withextra fields)

sabato 6 ottobre 12

Page 21: Back-end with SonataAdminBundle (and Symfony2, of course...)

EDIT / CREATE FORM

SYMFONYDAY 2012

Click to choose association

List ViewModal windows ;)

Opera

sabato 6 ottobre 12

Page 22: Back-end with SonataAdminBundle (and Symfony2, of course...)

EDIT / CREATE FORM

SYMFONYDAY 2012

Creating a new associated Entity

Create Form

Etichette

sabato 6 ottobre 12

Page 23: Back-end with SonataAdminBundle (and Symfony2, of course...)

EDIT / CREATE FORM

SYMFONYDAY 2012

Model type

Custom visualization

Help inline

Form Mapper

Collection type

sabato 6 ottobre 12

Page 24: Back-end with SonataAdminBundle (and Symfony2, of course...)

MAYBE NOT EVERYONE KNOWS THAT...

SYMFONYDAY 2012

Custom field block

Form fields template

sabato 6 ottobre 12

Page 25: Back-end with SonataAdminBundle (and Symfony2, of course...)

OTHER FEATURES

SYMFONYDAY 2012

•Controller for custom and batch actions•Lifecycle Callbacks•Validation•Advanced Templates customization•Pagination•Sidebar & Menu (via KnpMenuBundle)•Translations (10+ languages, Italian included)•ACL / Security Layer (SonataUserBundle + FOSUserBundle)•CLI Utility (app/console sonata:admin:*)

http://sonata-project.org/bundles/admin/2-0/doc/index.html

sabato 6 ottobre 12

Page 26: Back-end with SonataAdminBundle (and Symfony2, of course...)

CONCLUSIONI

SYMFONYDAY 2012

•Very powerful and flexible•Active community (>260 fork, >50 contrib)

•Stable release near for sf2.0... but still missing•Documentation is sometimes lacking

•Unstable “master” version (for sf2.1)

Being a Good OSS Contributor - Jeremy Mikola (http://joind.in/talk/view/7216)

sabato 6 ottobre 12

Page 27: Back-end with SonataAdminBundle (and Symfony2, of course...)

Questions?

SYMFONYDAY 2012sabato 6 ottobre 12

Page 28: Back-end with SonataAdminBundle (and Symfony2, of course...)

SYMFONYDAY 2012

GrazieSo long, and thanks for all the fish! ;)

@ottimohttps://github.com/andreadelfino

[email protected]

Thanks to Thomas Rabaix (@th0masr) for support and Lineke Kerckhoffs-Willems (@the_linie) for presentation tips.

sabato 6 ottobre 12