SlideShare une entreprise Scribd logo
1  sur  12
Télécharger pour lire hors ligne
Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 1/12InfoSaône - Tony Galmiche
Création de Bundle
avec Symfony
Présenté par Tony Galmiche
Human Talk aux Docks Numérique le 8 juillet 2014
Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 2/12InfoSaône - Tony Galmiche
Présentation de Symfony
http://symfony.com/
Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 3/12InfoSaône - Tony Galmiche
Présentation de Packagist
https://packagist.org/
Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 4/12InfoSaône - Tony Galmiche
Installation avec Composer et Packagist
curl -s https://getcomposer.org/installer | php
Installation de composer pour gérer les dépendances des modules :
Installation de Symfony avec composer et Packagist :
php composer.phar create-project symfony/framework-
standard-edition path_project_symfony 2.5.*
Configuration :
http://localhost/config.php
Environnement de développement:
Configuration :
http://localhost/app_dev.php/
Documentation : http://symfony.com/fr/doc/master/book/installation.html
Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 5/12InfoSaône - Tony Galmiche
Environnement de démo par défaut
Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 6/12InfoSaône - Tony Galmiche
Création d'un Bundle (Module)
php app/console generate:bundle
--namespace=Acme/HelloBundle --format=yml
Création du Bundle :
Enregistrement du Bundle :
public function registerBundles()
{
$bundles = array(
// ...
new AcmeHelloBundleAcmeHelloBundle(),
Routage :
# app/config/routing.yml
acme_hello:
resource:
"@AcmeHelloBundle/Resources/config/routing.yml"
prefix: /
Doc : http://symfony.com/fr/doc/master/book/page_creation.html
Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 7/12InfoSaône - Tony Galmiche
Contrôleur et vue avec Twig
Contrôleur :
class HelloController extends Controller {
public function indexAction($name) {
return $this->render(
'AcmeHelloBundle:Hello:index.html.twig',
array('name' => $name));
}
}
Vue :
{# src/Acme/HelloBundle/Resources/views/Hello/index.html.twig #}
{% extends '::base.html.twig' %}
{% block body %}
Hello {{ name }}!
{% endblock %}
Doc : http://symfony.com/fr/doc/master/book/page_creation.html
Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 8/12InfoSaône - Tony Galmiche
Doctrine et les bases de données
Création d'une entité (table) :
php app/console doctrine:generate:entity 
--entity="AcmeStoreBundle:Product" 
--fields="name:string(255) price:float
description:text"
Class générée :
// src/Acme/StoreBundle/Entity/Product.php
namespace AcmeStoreBundleEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity
* @ORMTable(name="product")
*/
class Product
{
/**
* @ORMId
* @ORMColumn(type="integer")
* @ORMGeneratedValue(strategy="AUTO")
*/
protected $id;
Doc : http://symfony.com/fr/doc/master/book/doctrine.html
Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 9/12InfoSaône - Tony Galmiche
Manipulation des données
avec le contrôleur
// src/Acme/StoreBundle/Controller/DefaultController.php
use AcmeStoreBundleEntityProduct;
use SymfonyComponentHttpFoundationResponse;
public function createAction()
{
$product = new Product();
$product->setName('A Foo Bar');
$product->setPrice('19.99');
$product->setDescription('Lorem ipsum dolor');
$em = $this->getDoctrine()->getManager();
$em->persist($product);
$em->flush();
return new Response('Id du produit créé : '.$product->getId());
}
Doc : http://symfony.com/fr/doc/master/book/doctrine.html
Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 10/12InfoSaône - Tony Galmiche
Générer un contrôleur CRUD
basé sur une entité Doctrine
Création du contrôleur avec les méthodes Create, Read, Update et Delete
(CRUD) :
php app/console generate:doctrine:crud
--entity=AcmeBlogBundle:Post
--format=annotation
--with-write
--no-interaction
Doc : http://symfony.com/fr/doc/master/bundles/SensioGeneratorBundle/commands/generate_doctrine_crud.html
Cette commande va générer le contrôleur CRUD mais également les
vues twig associées pour pouvoir manipuler l'entité concernée.
Cela va donc générer les formulaires pour créer, modifier, supprimer ou
consulter les données.
Ensuite il suffira d’utiliser twig pour mettre en page les formulaires par
exemple avec l'aide de Bootstrap
Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 11/12InfoSaône - Tony Galmiche
Exemple de réalisation
Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 12/12InfoSaône - Tony Galmiche
F i n
des questions ?

Contenu connexe

Tendances

Mieux Développer en PHP avec Symfony
Mieux Développer en PHP avec SymfonyMieux Développer en PHP avec Symfony
Mieux Développer en PHP avec SymfonyHugo Hamon
 
Presentation Symfony
Presentation SymfonyPresentation Symfony
Presentation SymfonyJeremy Gachet
 
Symfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesSymfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesNoel GUILBERT
 
Presentation du framework symfony
Presentation du framework symfonyPresentation du framework symfony
Presentation du framework symfonyJeremy Gachet
 
Introduction à Symfony2
Introduction à Symfony2Introduction à Symfony2
Introduction à Symfony2Hugo Hamon
 
Symfony2 Presentation
Symfony2 PresentationSymfony2 Presentation
Symfony2 Presentationyllieth
 
Symfony3 overview
Symfony3 overviewSymfony3 overview
Symfony3 overviewSymfonyMu
 
Une application en deux heure - PHP Québec Janvier 2009
Une application en deux heure - PHP Québec Janvier 2009Une application en deux heure - PHP Québec Janvier 2009
Une application en deux heure - PHP Québec Janvier 2009Philippe Gamache
 
Soutenance Zend Framework vs Symfony
Soutenance Zend Framework vs SymfonySoutenance Zend Framework vs Symfony
Soutenance Zend Framework vs SymfonyVincent Composieux
 
symfony : Un Framework Open-Source pour les Professionnels
symfony : Un Framework Open-Source pour les Professionnelssymfony : Un Framework Open-Source pour les Professionnels
symfony : Un Framework Open-Source pour les ProfessionnelsFabien Potencier
 
Formation Symfony2 par KNP Labs
Formation Symfony2 par KNP LabsFormation Symfony2 par KNP Labs
Formation Symfony2 par KNP LabsKNP Labs
 
Exposer des services web SOAP et REST avec symfony 1.4 et Zend Framework
Exposer des services web SOAP et REST avec symfony 1.4 et Zend FrameworkExposer des services web SOAP et REST avec symfony 1.4 et Zend Framework
Exposer des services web SOAP et REST avec symfony 1.4 et Zend FrameworkHugo Hamon
 
Utiliser le Zend Framework avec Symfony
Utiliser le Zend Framework avec SymfonyUtiliser le Zend Framework avec Symfony
Utiliser le Zend Framework avec SymfonyXavier Gorse
 
Atelier symfony n 1
Atelier symfony n 1Atelier symfony n 1
Atelier symfony n 1Amir Souissi
 
wallabag, comment on a migré vers symfony3
wallabag, comment on a migré vers symfony3wallabag, comment on a migré vers symfony3
wallabag, comment on a migré vers symfony3Nicolas Lœuillet
 
Plateforme De DéVeloppement En Php5 (Zend + Doctrine)
Plateforme De DéVeloppement En Php5 (Zend + Doctrine)Plateforme De DéVeloppement En Php5 (Zend + Doctrine)
Plateforme De DéVeloppement En Php5 (Zend + Doctrine)cornnery
 
Procédure de configuration et préparation de l’environnement sous windows
Procédure de configuration et préparation de l’environnement sous windowsProcédure de configuration et préparation de l’environnement sous windows
Procédure de configuration et préparation de l’environnement sous windowsAddi Ait-Mlouk
 
AFUP Aix/Marseille - 16 mai 2017 - Open API
AFUP Aix/Marseille - 16 mai 2017 - Open APIAFUP Aix/Marseille - 16 mai 2017 - Open API
AFUP Aix/Marseille - 16 mai 2017 - Open APIRomain Cambien
 

Tendances (20)

Mieux Développer en PHP avec Symfony
Mieux Développer en PHP avec SymfonyMieux Développer en PHP avec Symfony
Mieux Développer en PHP avec Symfony
 
Presentation Symfony
Presentation SymfonyPresentation Symfony
Presentation Symfony
 
Symfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesSymfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiques
 
Symfony Best Practices
Symfony Best PracticesSymfony Best Practices
Symfony Best Practices
 
Presentation du framework symfony
Presentation du framework symfonyPresentation du framework symfony
Presentation du framework symfony
 
Introduction à Symfony2
Introduction à Symfony2Introduction à Symfony2
Introduction à Symfony2
 
Symfony2 Presentation
Symfony2 PresentationSymfony2 Presentation
Symfony2 Presentation
 
Symfony3 overview
Symfony3 overviewSymfony3 overview
Symfony3 overview
 
Une application en deux heure - PHP Québec Janvier 2009
Une application en deux heure - PHP Québec Janvier 2009Une application en deux heure - PHP Québec Janvier 2009
Une application en deux heure - PHP Québec Janvier 2009
 
Soutenance Zend Framework vs Symfony
Soutenance Zend Framework vs SymfonySoutenance Zend Framework vs Symfony
Soutenance Zend Framework vs Symfony
 
symfony : Un Framework Open-Source pour les Professionnels
symfony : Un Framework Open-Source pour les Professionnelssymfony : Un Framework Open-Source pour les Professionnels
symfony : Un Framework Open-Source pour les Professionnels
 
Formation Symfony2 par KNP Labs
Formation Symfony2 par KNP LabsFormation Symfony2 par KNP Labs
Formation Symfony2 par KNP Labs
 
Exposer des services web SOAP et REST avec symfony 1.4 et Zend Framework
Exposer des services web SOAP et REST avec symfony 1.4 et Zend FrameworkExposer des services web SOAP et REST avec symfony 1.4 et Zend Framework
Exposer des services web SOAP et REST avec symfony 1.4 et Zend Framework
 
PHP5 et Zend Framework
PHP5 et Zend FrameworkPHP5 et Zend Framework
PHP5 et Zend Framework
 
Utiliser le Zend Framework avec Symfony
Utiliser le Zend Framework avec SymfonyUtiliser le Zend Framework avec Symfony
Utiliser le Zend Framework avec Symfony
 
Atelier symfony n 1
Atelier symfony n 1Atelier symfony n 1
Atelier symfony n 1
 
wallabag, comment on a migré vers symfony3
wallabag, comment on a migré vers symfony3wallabag, comment on a migré vers symfony3
wallabag, comment on a migré vers symfony3
 
Plateforme De DéVeloppement En Php5 (Zend + Doctrine)
Plateforme De DéVeloppement En Php5 (Zend + Doctrine)Plateforme De DéVeloppement En Php5 (Zend + Doctrine)
Plateforme De DéVeloppement En Php5 (Zend + Doctrine)
 
Procédure de configuration et préparation de l’environnement sous windows
Procédure de configuration et préparation de l’environnement sous windowsProcédure de configuration et préparation de l’environnement sous windows
Procédure de configuration et préparation de l’environnement sous windows
 
AFUP Aix/Marseille - 16 mai 2017 - Open API
AFUP Aix/Marseille - 16 mai 2017 - Open APIAFUP Aix/Marseille - 16 mai 2017 - Open API
AFUP Aix/Marseille - 16 mai 2017 - Open API
 

En vedette

Chiffres arabes.np.tous
Chiffres arabes.np.tousChiffres arabes.np.tous
Chiffres arabes.np.tousAndromede56
 
PLAN DESCONTAMINACION RIO CUTUCHI
PLAN DESCONTAMINACION RIO CUTUCHIPLAN DESCONTAMINACION RIO CUTUCHI
PLAN DESCONTAMINACION RIO CUTUCHIFernando Cáceres
 
Options secteurs t et p
Options secteurs t et pOptions secteurs t et p
Options secteurs t et pgillesroman
 
Présentation de projet ÉS
Présentation de projet ÉSPrésentation de projet ÉS
Présentation de projet ÉSchapdelainef
 
CROSS Départemental 2013 college ONET
CROSS Départemental 2013 college ONETCROSS Départemental 2013 college ONET
CROSS Départemental 2013 college ONETDG WEB
 
Trust und Interest Similarity und deren Anwendung für Empfehlungssysteme
Trust und Interest Similarity und deren Anwendung für EmpfehlungssystemeTrust und Interest Similarity und deren Anwendung für Empfehlungssysteme
Trust und Interest Similarity und deren Anwendung für EmpfehlungssystemeFlorian Stegmaier
 
Miami, por Gerardo y Ricardo de 3C
Miami, por Gerardo y Ricardo de 3CMiami, por Gerardo y Ricardo de 3C
Miami, por Gerardo y Ricardo de 3CJuan Diego Peñas
 
Personalmanager bite kennzahlen
Personalmanager bite kennzahlenPersonalmanager bite kennzahlen
Personalmanager bite kennzahlenBITE GmbH
 
Verbes pronominaux
Verbes pronominauxVerbes pronominaux
Verbes pronominauxjkgandy
 
Compte rendu n°1 observatoire de l'inspiration
Compte rendu n°1  observatoire de l'inspiration Compte rendu n°1  observatoire de l'inspiration
Compte rendu n°1 observatoire de l'inspiration George-Bailey
 

En vedette (20)

Presentation symfony
Presentation symfonyPresentation symfony
Presentation symfony
 
Tutoriel java
Tutoriel javaTutoriel java
Tutoriel java
 
Chiffres arabes.np.tous
Chiffres arabes.np.tousChiffres arabes.np.tous
Chiffres arabes.np.tous
 
PLAN DESCONTAMINACION RIO CUTUCHI
PLAN DESCONTAMINACION RIO CUTUCHIPLAN DESCONTAMINACION RIO CUTUCHI
PLAN DESCONTAMINACION RIO CUTUCHI
 
Options secteurs t et p
Options secteurs t et pOptions secteurs t et p
Options secteurs t et p
 
El Sistema Solar TIC Loyola
El Sistema Solar TIC LoyolaEl Sistema Solar TIC Loyola
El Sistema Solar TIC Loyola
 
Présentation de projet ÉS
Présentation de projet ÉSPrésentation de projet ÉS
Présentation de projet ÉS
 
GIS Solutions
GIS SolutionsGIS Solutions
GIS Solutions
 
CROSS Départemental 2013 college ONET
CROSS Départemental 2013 college ONETCROSS Départemental 2013 college ONET
CROSS Départemental 2013 college ONET
 
Trust und Interest Similarity und deren Anwendung für Empfehlungssysteme
Trust und Interest Similarity und deren Anwendung für EmpfehlungssystemeTrust und Interest Similarity und deren Anwendung für Empfehlungssysteme
Trust und Interest Similarity und deren Anwendung für Empfehlungssysteme
 
Fútbol
FútbolFútbol
Fútbol
 
Miami, por Gerardo y Ricardo de 3C
Miami, por Gerardo y Ricardo de 3CMiami, por Gerardo y Ricardo de 3C
Miami, por Gerardo y Ricardo de 3C
 
Personalmanager bite kennzahlen
Personalmanager bite kennzahlenPersonalmanager bite kennzahlen
Personalmanager bite kennzahlen
 
Sida Solidarité Magazine N°4
Sida Solidarité Magazine N°4Sida Solidarité Magazine N°4
Sida Solidarité Magazine N°4
 
Ar
Ar Ar
Ar
 
Verbes pronominaux
Verbes pronominauxVerbes pronominaux
Verbes pronominaux
 
Avions
AvionsAvions
Avions
 
Rapport d'activité 2013
Rapport d'activité 2013Rapport d'activité 2013
Rapport d'activité 2013
 
Rosario
RosarioRosario
Rosario
 
Compte rendu n°1 observatoire de l'inspiration
Compte rendu n°1  observatoire de l'inspiration Compte rendu n°1  observatoire de l'inspiration
Compte rendu n°1 observatoire de l'inspiration
 

Similaire à Présentation de symfony - Human talks aux docks le 8 juillet 2014

La Console Symfony
La Console Symfony La Console Symfony
La Console Symfony Imad ZAIRIG
 
Retour d'expérience technique Go, gRPC, Kubernetes
Retour d'expérience technique Go, gRPC, KubernetesRetour d'expérience technique Go, gRPC, Kubernetes
Retour d'expérience technique Go, gRPC, KubernetesVincent Composieux
 
Installation magento 2 avec mamp
 Installation magento 2 avec mamp Installation magento 2 avec mamp
Installation magento 2 avec mampBlackbird
 
Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014Les-Tilleuls.coop
 
Formation Play! framework
Formation Play! frameworkFormation Play! framework
Formation Play! frameworkBenoît Simard
 
Distribuer une application avec Symfony & Docker *
Distribuer une application avec Symfony & Docker *Distribuer une application avec Symfony & Docker *
Distribuer une application avec Symfony & Docker *Thierry M.
 
Présentation de EasyAdmin, le bundle d'admin de Symfony
Présentation de EasyAdmin, le bundle d'admin de SymfonyPrésentation de EasyAdmin, le bundle d'admin de Symfony
Présentation de EasyAdmin, le bundle d'admin de SymfonyRaphaël Kueny
 
Formation wp contenu - livret
Formation wp   contenu - livretFormation wp   contenu - livret
Formation wp contenu - livretCaroleTherrien1
 
Communications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHPCommunications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHPjulien pauli
 
À La découverte de flow3 - t3con12
À La découverte de flow3 -  t3con12À La découverte de flow3 -  t3con12
À La découverte de flow3 - t3con12mguermazi
 
retour sur confoo2011 et Symfony2
retour sur confoo2011 et Symfony2retour sur confoo2011 et Symfony2
retour sur confoo2011 et Symfony2Saad Tazi
 
Php 7.4 2020-01-28 - afup
Php 7.4   2020-01-28 - afupPhp 7.4   2020-01-28 - afup
Php 7.4 2020-01-28 - afupJulien Vinber
 
Symfony 4 2019
Symfony 4 2019Symfony 4 2019
Symfony 4 2019Eric Para
 

Similaire à Présentation de symfony - Human talks aux docks le 8 juillet 2014 (20)

Playing With PHP 5.3
Playing With PHP 5.3Playing With PHP 5.3
Playing With PHP 5.3
 
La Console Symfony
La Console Symfony La Console Symfony
La Console Symfony
 
Retour d'expérience technique Go, gRPC, Kubernetes
Retour d'expérience technique Go, gRPC, KubernetesRetour d'expérience technique Go, gRPC, Kubernetes
Retour d'expérience technique Go, gRPC, Kubernetes
 
Installation magento 2 avec mamp
 Installation magento 2 avec mamp Installation magento 2 avec mamp
Installation magento 2 avec mamp
 
Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014
 
Formation Play! framework
Formation Play! frameworkFormation Play! framework
Formation Play! framework
 
Symfony vs laravel
Symfony vs  laravelSymfony vs  laravel
Symfony vs laravel
 
Distribuer une application avec Symfony & Docker *
Distribuer une application avec Symfony & Docker *Distribuer une application avec Symfony & Docker *
Distribuer une application avec Symfony & Docker *
 
UserGroup Varnish - eZ
UserGroup Varnish - eZUserGroup Varnish - eZ
UserGroup Varnish - eZ
 
Paug aosp ice-creamsandwich_20120119
Paug aosp ice-creamsandwich_20120119Paug aosp ice-creamsandwich_20120119
Paug aosp ice-creamsandwich_20120119
 
Présentation de EasyAdmin, le bundle d'admin de Symfony
Présentation de EasyAdmin, le bundle d'admin de SymfonyPrésentation de EasyAdmin, le bundle d'admin de Symfony
Présentation de EasyAdmin, le bundle d'admin de Symfony
 
Formation wp contenu - livret
Formation wp   contenu - livretFormation wp   contenu - livret
Formation wp contenu - livret
 
Communications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHPCommunications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHP
 
Vagrant - Concept
Vagrant - ConceptVagrant - Concept
Vagrant - Concept
 
À La découverte de flow3 - t3con12
À La découverte de flow3 -  t3con12À La découverte de flow3 -  t3con12
À La découverte de flow3 - t3con12
 
retour sur confoo2011 et Symfony2
retour sur confoo2011 et Symfony2retour sur confoo2011 et Symfony2
retour sur confoo2011 et Symfony2
 
Tpag appli-galaxy
Tpag appli-galaxyTpag appli-galaxy
Tpag appli-galaxy
 
Docker@linuq
Docker@linuqDocker@linuq
Docker@linuq
 
Php 7.4 2020-01-28 - afup
Php 7.4   2020-01-28 - afupPhp 7.4   2020-01-28 - afup
Php 7.4 2020-01-28 - afup
 
Symfony 4 2019
Symfony 4 2019Symfony 4 2019
Symfony 4 2019
 

Présentation de symfony - Human talks aux docks le 8 juillet 2014

  • 1. Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 1/12InfoSaône - Tony Galmiche Création de Bundle avec Symfony Présenté par Tony Galmiche Human Talk aux Docks Numérique le 8 juillet 2014
  • 2. Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 2/12InfoSaône - Tony Galmiche Présentation de Symfony http://symfony.com/
  • 3. Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 3/12InfoSaône - Tony Galmiche Présentation de Packagist https://packagist.org/
  • 4. Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 4/12InfoSaône - Tony Galmiche Installation avec Composer et Packagist curl -s https://getcomposer.org/installer | php Installation de composer pour gérer les dépendances des modules : Installation de Symfony avec composer et Packagist : php composer.phar create-project symfony/framework- standard-edition path_project_symfony 2.5.* Configuration : http://localhost/config.php Environnement de développement: Configuration : http://localhost/app_dev.php/ Documentation : http://symfony.com/fr/doc/master/book/installation.html
  • 5. Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 5/12InfoSaône - Tony Galmiche Environnement de démo par défaut
  • 6. Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 6/12InfoSaône - Tony Galmiche Création d'un Bundle (Module) php app/console generate:bundle --namespace=Acme/HelloBundle --format=yml Création du Bundle : Enregistrement du Bundle : public function registerBundles() { $bundles = array( // ... new AcmeHelloBundleAcmeHelloBundle(), Routage : # app/config/routing.yml acme_hello: resource: "@AcmeHelloBundle/Resources/config/routing.yml" prefix: / Doc : http://symfony.com/fr/doc/master/book/page_creation.html
  • 7. Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 7/12InfoSaône - Tony Galmiche Contrôleur et vue avec Twig Contrôleur : class HelloController extends Controller { public function indexAction($name) { return $this->render( 'AcmeHelloBundle:Hello:index.html.twig', array('name' => $name)); } } Vue : {# src/Acme/HelloBundle/Resources/views/Hello/index.html.twig #} {% extends '::base.html.twig' %} {% block body %} Hello {{ name }}! {% endblock %} Doc : http://symfony.com/fr/doc/master/book/page_creation.html
  • 8. Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 8/12InfoSaône - Tony Galmiche Doctrine et les bases de données Création d'une entité (table) : php app/console doctrine:generate:entity --entity="AcmeStoreBundle:Product" --fields="name:string(255) price:float description:text" Class générée : // src/Acme/StoreBundle/Entity/Product.php namespace AcmeStoreBundleEntity; use DoctrineORMMapping as ORM; /** * @ORMEntity * @ORMTable(name="product") */ class Product { /** * @ORMId * @ORMColumn(type="integer") * @ORMGeneratedValue(strategy="AUTO") */ protected $id; Doc : http://symfony.com/fr/doc/master/book/doctrine.html
  • 9. Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 9/12InfoSaône - Tony Galmiche Manipulation des données avec le contrôleur // src/Acme/StoreBundle/Controller/DefaultController.php use AcmeStoreBundleEntityProduct; use SymfonyComponentHttpFoundationResponse; public function createAction() { $product = new Product(); $product->setName('A Foo Bar'); $product->setPrice('19.99'); $product->setDescription('Lorem ipsum dolor'); $em = $this->getDoctrine()->getManager(); $em->persist($product); $em->flush(); return new Response('Id du produit créé : '.$product->getId()); } Doc : http://symfony.com/fr/doc/master/book/doctrine.html
  • 10. Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 10/12InfoSaône - Tony Galmiche Générer un contrôleur CRUD basé sur une entité Doctrine Création du contrôleur avec les méthodes Create, Read, Update et Delete (CRUD) : php app/console generate:doctrine:crud --entity=AcmeBlogBundle:Post --format=annotation --with-write --no-interaction Doc : http://symfony.com/fr/doc/master/bundles/SensioGeneratorBundle/commands/generate_doctrine_crud.html Cette commande va générer le contrôleur CRUD mais également les vues twig associées pour pouvoir manipuler l'entité concernée. Cela va donc générer les formulaires pour créer, modifier, supprimer ou consulter les données. Ensuite il suffira d’utiliser twig pour mettre en page les formulaires par exemple avec l'aide de Bootstrap
  • 11. Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 11/12InfoSaône - Tony Galmiche Exemple de réalisation
  • 12. Présentation de Symfony - Human Talk aux Docks le 8 juillet 2014 Page 12/12InfoSaône - Tony Galmiche F i n des questions ?