We'll not speak about SILEX

Symfony CRUD in 10 minutes

How to build a web app writing only a single line of php code

Create a Sandbox

$ composer create-project symfony/framework-standard-edition newProject

Create your layout

<!DOCTYPE html>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>{% block title 'My admin' %}</title>
        <link rel="shortcut icon" href="{{ asset('favicon.ico') }}" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        {% block stylesheets %}
            <link href="//"
            <link href="//"
        {% endblock %}
        <nav class="navbar navbar-fixed-top">
            <!-- put your nav bar here -->
        <div class="container">
            {% block body '' %}
        {% block javascripts %}
            <script src="//"></script>
            <script src="//">
        {% endblock %}

Mentally thank the President

Add PUGXGeneratorBundle as a dependency

$ composer require pugx/generator-bundle:2.4.* --dev

First line of code: load the bundle into the symfony kernel

// app/AppKernel.php

public function registerBundles()
    // ...
    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        // ...
        $bundles[] = new PUGX\GeneratorBundle\PUGXGeneratorBundle();

N.B. These steps are the same for every application! So you can prepare a repo containing everything and start there next time!

Create your first Bundle

$ app/console g:b
$ app/console generate:bundle

but I'm lazy, so

Download the symfony 2.6 Bootstrap form

$ wget

$ mkdir src/Acme/CRUDBundle/Resources/views/Form

$ mv bootstrap_3_layout.html.twig src/Acme/CRUDBundle/Resources/views/Form/bootstrap_3_layout.html.twig

Generate an Entity

$ app/console g:d:entity

Create the shema

$ app/console doc:schema:create

Finally generate the CRUD

$ php app/console pugx:generate:crud                           \
      --entity=AcmeCRUDBundle:Post                             \
      --layout=::base.html.twig                                \
      --theme=AcmeCRUDBundle:Form:bootstrap_3_layout.html.twig \
$ app/console server:run


Wait, I know... And What about SILEX?!?


Wait, wait... I Know! Why you hate CRUD?!?

I don't hate the CRUD...


...the CRUD hates me

  • Entities are not only data containers

  • Rarely use cases are aligned with the CRUD of a single entity, but usually involves several different entities

  • Handle and dispose domain objects in the presentation layer does not allow us to protect the invariants

  • Every time you write a CRUD, god kills a kitten

It's your choice!

Silex is a (Fat) microframework

Framework : Service = MicroFramework : MicroService

  • Persistence
  • Templating
  • Form handling

CRUD  Requires

It's your choice!

Made with