SlideShare une entreprise Scribd logo
1  sur  47
Télécharger pour lire hors ligne
Une application
                            en deux heures
                               Avec Symfony




vendredi 13 novembre 2009                     1
Objectif


                 • Présenter symfony d’une façon
                        originale

                 • Faire une application en une heure




vendredi 13 novembre 2009                               2
Qui suis-je?

            • Philippe Gamache
              •Expert en sécurité PHP
               chez Sensio Labs
              •Auteur du livre « Sécurité
               PHP 5 et MySQL » avec
               Damien Seguy, chez
               Eyrolles
              •http://www.phportail.net
              •http://lapageamelkor.org
              •naheulbeukauquebec.ca



vendredi 13 novembre 2009                    3
Des
           questions?


                                  ?
                    N’attendez
                    pas à la fin




vendredi 13 novembre 2009             4
L’application


                 • Blogue
                        • Commentaires
                        • URLs propres




vendredi 13 novembre 2009                      5
symfony
                 • Cadre d’application WEB en PHP
                 • Basé sur :
                        • 10 ans d’expérience chez Sensio
                        • D’autres logiciels libres existants
                 • Licence MIT
                 • Documentation est libre
                 • Grande communauté

vendredi 13 novembre 2009                                       6
symfony

                 • Créer pour:
                   • Sites web professionnels
                   • Besoins complexes
                   • Environnements exigeants
                   • Développement rapide


vendredi 13 novembre 2009                       7
Installer symfony

         http://www.symfony-project.org/installation
                 • Source
                 • Bac à sable
                 • Installation via PEAR
                 • Installation via SVN
                 • Installation Linux (Debian et SUSE)

vendredi 13 novembre 2009                                8
Installation PEAR
      pear channel-discover pear.symfony-project.com
                            pear install symfony/symfony-1.2.1




vendredi 13 novembre 2009                                        9
Création du projet
              • Créer le répertoire du projet
                $ mkdir -p blogue
                $ cd blogue
              • Vérifier la version de symfony
                $ symfony -V
              • Créer un projet
                $ symfony generate:project blogue




vendredi 13 novembre 2009                           10
Création du projet
              • Créer une application
                $ symfony generate:app /
                  --escaping-strategy=on /
                  --csrf-secret=UniqueSecret /
                  frontend
              • Ajuster votre serveur web




vendredi 13 novembre 2009                        11
http://blogue.local/frontend_dev.php/


vendredi 13 novembre 2009                             12
Activation de sfDoctrine
                      // config/ProjectConfiguration.class.php
                      public function setup()
                      {
                        $this->enableAllPluginsExcept(
                          array('sfPropelPlugin',
                                'sfCompat10Plugin'));
                      }




vendredi 13 novembre 2009                                        13
La base de données
                 • Créer la base de données
                     $ mysqladmin -uroot -pmYsEcret /
                       create jobeet
                 • Configurer le projet
                     $ symfony configure:database /
                       --name=doctrine /
                       --class=sfDoctrineDatabase /
                       "mysql:host=localhost;dbname=blogue" /
                       root mYsEcret
                 • Effacer la connexion de Propel

vendredi 13 novembre 2009                                   14
Plugiciels
                 • Installer les plugiciels
             http://www.symfony-project.org/plugins/
                 • sfDoctrineGuardPlugin
                       $ symfony plugin:install /
                         sfDoctrineGuardPlugin /
                         --release=3.0.0




vendredi 13 novembre 2009                              15
Le modèle




vendredi 13 novembre 2009               16
Le schéma
     # config/doctrine/schema.yml
     actAs: [Timestampable]
     BlogPost:
       actAs:
         Timestampable: ~
         Sluggable:
           fields: [title]               BlogComment:
           unique: true                    columns:
       columns:                              blog_post_id: integer
         is_published:                       author_name: string(255)
           type: boolean                     author_email: string(255)
           default: false                    author_url: string(255)
         allow_comments:                     content: string(5000)
           type: boolean                   relations:
           default: true                     BlogPost:
         author_id: integer(4)                 local: blog_post_id
         title: string(255)                    foreign: id
         content: string(500000)               type: one
         published_at: date                    foreignAlias: Comments
       relations:
         Author:
           class: sfGuardUser
           local: author_id
           foreign: id
           type: one



vendredi 13 novembre 2009                                                17
Données de tests
               # data/fixtures/fixtures.yml
               sfGuardUser:
                 philippeg:
                   username: Philippe Gamache
                   password: password
                   is_super_admin: true

               sfGuardPermission:
                 sgp_admin:
                   name:            admin
                   description:     Administrator permission

               sfGuardGroup:
                 sgg_admin:
                   name:            admin
                   description:     Administrator group

               sfGuardGroupPermission:
                 sggp_admin:
                   sfGuardGroup:       sgg_admin
                   sfGuardPermission: sgp_admin

               sfGuardUserGroup:
                 sgug_admin:
                   sfGuardGroup:        sgg_admin
                   sfGuardUser:         philippeg


vendredi 13 novembre 2009                                      18
Données de tests
          BlogPost:
            post_1:
              Author: philippeg
              title: Lorem ipsum dolor sit amet
              content: |
                <p>Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...</p>
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do...</p>
              is_published: true
              published_at: 09-01-07
            post_2:
              Author: philippeg
              title: Ut enim ad minim veniam
              content: |
                <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
                <p>Duis aute irure dolor in reprehenderit in voluptate velit esse...</p>
              is_published: true
              published_at: 09-01-07
            post_3:
              Author: philippeg
              title: Duis aute irure dolor in reprehenderit in voluptate
              content: |
                <p>Duis aute irure dolor in reprehenderit in voluptate velit esse...</p>
                <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
              is_published: true
              published_at: 09-01-07
          ...


vendredi 13 novembre 2009                                                                      19
Données de tests
               BlogComment:
                 comment_1:
                   BlogPost: post_1
                   author_name: lorem
                   content: Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
               labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
               ullamco laboris nisi ut aliquip ex ea commodo consequat.
                 comment_2:
                   BlogPost: post_1
                   author_name: elit
                   content: Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
               dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
               sunt in culpa qui officia deserunt mollit anim id est laborum.
                 comment_3:
                   BlogPost: post_3
                   author_name: aute
                   content: Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
               officia deserunt mollit anim id est laborum.
                 comment_4:
                   BlogPost: post_3
                   author_name: aute
                   content: ESunt in culpa qui officia deserunt mollit anim id est laborum.




vendredi 13 novembre 2009                                                                           20
Création du code
                 • Utiliser le générateur de code
                  $ symfony doctrine:generate-crud /
                     --with-show frontend post BlogPost
                 • Effacer les actions inutiles
                        • executeNew()
                        • executeEdit()
                        • executeUpdate()
                        • executeDelete()
                        • processForm()

vendredi 13 novembre 2009                             21
Création du code
                 • Effacer les fichiers inutiles
                        • templates/_form.php
                        • templates/editSuccess.php
                        • templates/newSuccess.php
                 • Effacer les liens vers les autres
                        fonctions




vendredi 13 novembre 2009                              22
Création du code
                 • Modifier templates/indexSuccess.php
                       <?php foreach ($blog_post_list as $blog_post): ?>
                         <h2><?php echo link_to($blog_post->gettitle(), '@post_show?slug=' .
                       $blog_post->getslug()) ?></h2>
                         <div>Par <?php echo $blog_post->getAuthor() ?> le <?php echo
                       $blog_post->getpublished_at() ?></div>
                         <p>
                           <?php echo $blog_post->getContentSuccess() ?>
                         </p>
                         <p><?php echo link_to('Voir plus...', '@post_show?slug=' . $blog_post-
                       >getslug()) ?></p>
                         <br /><br />
                       <?php endforeach; ?>




vendredi 13 novembre 2009                                                                         23
Création du code
                 • Modifier templates/showSuccess.php
                       <h2><?php echo $blog_post->gettitle() ?></h2>
                       <div>Par <?php echo $blog_post->getAuthor() ?> le <?php echo $blog_post-
                       >getpublished_at() ?></div>

                       <p><?php echo nl2br($blog_post->getcontent()) ?></p>

                       <hr /><br /><br />

                       <?php echo link_to('List', '@homepage') ?>




vendredi 13 novembre 2009                                                                         24
Création du code
                 • Ajouter au templates/layout.php
                       <div id="header">
                         <h1><?php echo link_to('Mon Blogue', '@homepage') ?></h1>
                       </div>

                       <div id="content">
                         <?php echo $sf_data->getRaw('sf_content') ?>
                       </div>
                       <div id="footer"></div>


                 • Ajouter web/css/blog.css
                 • Modifier apps/frontend/config/view.yml


vendredi 13 novembre 2009                                                            25
Création du code
                 • Modifier actions.class.php
                            public function executeIndex(sfWebRequest $request)
                            {
                              $this->blog_post_list = Doctrine::getTable('BlogPost')
                                ->createQuery('a')
                                ->where('a.is_published = 1')
                                ->execute();
                            }

                            public function executeShow(sfWebRequest $request)
                            {
                              $this->blog_post = Doctrine::getTable('BlogPost')
                                ->findOneBySlug($request->getParameter('slug'));
                              $this->forward404Unless($this->blog_post);
                            }




vendredi 13 novembre 2009                                                              26
Création du code
                 • Modifier BlogPost.class.php
                            public function getContentSummary()
                            {
                              $out = explode('<', nl2br(substr($this->getcontent(), 0, 500)));
                              return $out[0] . '...';
                            }


                 • Ajouter à routing.yml
                       post_show:
                         url:   /:slug
                         param: { module: post, action: show }




vendredi 13 novembre 2009                                                                        27
Ajouter les
                            commentaires
                 • Utiliser le générateur de code
                       $ symfony doctrine:generate-crud /
                         frontend comment BlogComment
                 • Copier le code dont vous aurez besoin




vendredi 13 novembre 2009                                   28
Ajouter les
                                       commentaires
                 • Modifier le code dans actions.class.php
                            public function executeIndex(sfWebRequest $request)
                            {
                              $this->blog_post_list = Doctrine::getTable('BlogPost')
                                ->createQuery('p')
                                ->groupBy('p.published_at, p.id')
                                ->where('p.is_published = 1')
                                ->execute();
                            }

                            public function executeShow(sfWebRequest $request)
                            {
                              $this->blog_post = Doctrine::getTable('BlogPost')
                                ->findOneBySlug($request->getParameter('slug'));
                              $this->forward404Unless($this->blog_post);

                                $this->form = new BlogCommentForm();
                            }




vendredi 13 novembre 2009                                                              29
Ajouter les
                                       commentaires
                 • Ajouter le code dans actions.class.php
                            public function executeCreate(sfWebRequest $request)
                            {
                              $this->forward404Unless($request->isMethod('post'));
                              $this->blog_post = Doctrine::getTable('BlogPost')
                                ->findOneBySlug($request->getParameter('slug'));
                              $this->forward404Unless($this->blog_post);

                                $comment = new BlogComment();
                                $comment->setBlogPost($this->blog_post);

                                $this->form = new BlogCommentForm($comment);
                                $this->processForm($request, $this->form);

                                $this->setTemplate('show');
                            }




vendredi 13 novembre 2009                                                            30
Ajouter les
                                    commentaires
                 • Ajouter le code dans actions.class.php
                            public function processForm(sfWebRequest $request, sfForm $form)
                            {
                              $form->bind($request->getParameter($form->getName()));
                              if ($form->isValid())
                              {
                                $blog_comment = $form->save();
                                $this->redirect('@post_show?slug=' .
                                    $request->getParameter('slug'));
                              }
                            }

                 • Ajouter a routing.yml
                        comment:
                          url:   /comment/:slug
                          param: { module: post, action: create }




vendredi 13 novembre 2009                                                                      31
Ajouter les
                                  commentaires
                 • Modifier templates/showSuccess.php
                       ...
                       <p><?php echo nl2br($blog_post->getcontent()) ?></p>
                       <?php if (count($blog_post->getComments())): ?>
                         <ul id="comments">
                         <?php foreach ($blog_post->getComments() as $comment): ?>
                           <li class="comments">
                           <br />
                           <div class="bold">Poster <?php echo $comment->getcreated_at() ?> par
                       <?php echo $comment->getauthor_name() ?> le </div>
                           <p>
                              <?php echo $comment->getcontent() ?>
                           </p>
                           </li>
                         <?php endforeach; ?>
                         </ul>
                       <?php endif ?>
                       <br />
                       ...




vendredi 13 novembre 2009                                                                         32
Ajouter les
                                  commentaires
                 • Modifier templates/showSuccess.php
                       ...

                       <p class="bold">Ajouter votre commentaire</p>
                       <br />
                       <?php include_partial('form',
                           array('form' => $form, 'blog_post' => $blog_post)) ?>
                       <hr /><br /><br />

                       <?php echo link_to('List', '@homepage') ?>




vendredi 13 novembre 2009                                                          33
Ajouter les
                                  commentaires
                 • Modifier templates/indexSuccess.php
                       ...
                         <p>
                           <?php echo $blog_post->getContentSuccess() ?>
                         </p>
                         <p>Commentaire (<?php echo count($blog_post->getComments()) ?>) :
                         <?php echo link_to('Voir plus...', '@post_show?slug=' . $blog_post-
                       >getslug()) ?></p>
                         <br /><br />
                       <?php endforeach; ?>


                 • Déplacer _form.php




vendredi 13 novembre 2009                                                                      34
Ajouter les
                                  commentaires
                 • Modifier templates/_form.php
                       ...
                       <form action="<?php echo url_for('@comment?slug=' .
                         $blog_post->getSlug()) ?>" method="POST">
                       <?php if (!$form->getObject()->isNew()): ?>
                       <input type="hidden" name="sf_method" value="PUT" />
                       <?php endif; ?>
                         <table>
                       ...

                 • Garder que
                   • author_name
                   • author_email
                   • author_url
                   • content

vendredi 13 novembre 2009                                                     35
Ajouter les
                                       commentaires
                 • Modifier BlogCommentForm.class.php
                            public function configure()
                            {
                              unset(
                                 $this['created_at'], $this['updated_at'],
                                 $this['blog_post_id']
                              );

                                $this->validatorSchema['author_email'] =
                                    new sfValidatorEmail(array('required' => false));
                                $this->validatorSchema['author_url'] =
                                    new sfValidatorUrl(array('required' => false));

                                $this->widgetSchema->setLabels(array(
                                  'author_email' => 'Votre courriel ',
                                  'author_name'   => 'Votre nom ',
                                  'author_url'    => 'Site Web ',
                                  'content'       => 'Commentaire ',
                                ));
                            }




vendredi 13 novembre 2009                                                               36
Création du Backend
              • Créer une application
                     $ symfony generate:app /
                       --escaping-strategy=on /
                       --csrf-secret=UniqueSecret /
                       backend




vendredi 13 novembre 2009                             37
Création du Backend
              • Créer les modules
                     $ symfony generate:admin /
                       --module=post backend BlogPost
                     $ symfony generate:admin /
                       --module=comment backend /
                       BlogComment




vendredi 13 novembre 2009                               38
Création du Backend
              • Modifier routing.yml
                        sf_guard_signin:
                          url:   /login
                          param: { module: sfGuardAuth, action: signin }

                        sf_guard_signout:
                          url:   /logout
                          param: { module: sfGuardAuth, action: signout }

                        sf_guard_password:
                          url:   /request_password
                          param: { module: sfGuardAuth, action: password }

                        # default rules
                        homepage:
                          url:    /
                          param: { module: post, action: index }




vendredi 13 novembre 2009                                                    39
Création du Backend
                 • Ajouter au templates/layout.php
                       <div id="header">
                         <h1><?php echo link_to('Mon Blogue', '@homepage') ?></h1>
                       </div>

                       <div id="menu">
                         <ul>
                           <li><?php echo link_to('Poste', '@blog_post') ?></li>
                           <li><?php echo link_to('Commentaire', '@blog_comment') ?></li>
                         </ul>
                       </div>

                       <div id="content">
                         <?php echo $sf_data->getRaw('sf_content') ?>
                       </div>

                       <div id="footer"></div>


                 • Modifier apps/frontend/config/view.yml

vendredi 13 novembre 2009                                                                   40
Création du Backend
              • Modifier setting.yml
                        ...
                        all:
                          .actions:
                             login_module:       sfGuardAuth
                             login_action:       signin

                            secure_module:       sfGuardAuth
                            secure_action:       secure
                          .settings:
                            enabled_modules:   [default, sfGuardAuth]
                        ...

              • Modifier setting.yml
                        default:
                          is_secure: on




vendredi 13 novembre 2009                                               41
Création du Backend
              • Modifier post generator.yml
                        ...
                              config:
                                actions: ~
                                fields: ~
                                list:
                                  title:   Liste de message
                                  display: [is_published, author_id, =title, published_at]
                                filter:
                                  display: [is_published]
                                form:    ~
                                edit:
                                  title: Modifier le message "%%title%%"
                                  display: [is_published, author_id, title, content, published_at]
                                new:
                                  title: Nouveau message
                                  display: [is_published, author_id, title, content, published_at]




vendredi 13 novembre 2009                                                                            42
Création du Backend
              • Modifier comment generator.yml
                        ...
                              config:
                                actions: ~
                                  _delete: ~
                                  _list: ~
                                fields:
                                  ContentSummary:
                                     label: Commentaires
                                list:
                                  object_actions:
                                     _delete: ~
                                  actions:
                                     __: ~
                                  title:    Liste des commentaires
                                  display: [blog_post_id, =author_name, =ContentSummary]
                                filter:
                                  display: [blog_post_id]
                                form:     ~
                                edit:     ~
                                new:      ~



vendredi 13 novembre 2009                                                                  43
Création du Backend
              • Modifier myUser.class.php
                        class myUser extends sfGuardSecurityUser
                        {
                        }




vendredi 13 novembre 2009                                          44
Pour aller plus loins

                 • Ajouter étiquettes (tags)
                 • Ajouter un mini-calendrier
                 • Mettre les billets par mois
                 • Ajouter recherche par date
                 • Ajouter des flux de données (RSS,
                        ATOM) via sfFeed2plugins


vendredi 13 novembre 2009                             45
Questions?

  philippe.gamache@symfony-project.com
                 info@ph-il.ca
       http://www.symfoy-project.org
          http://www.phportail.net


vendredi 13 novembre 2009                46
vendredi 13 novembre 2009   47

Contenu connexe

Tendances

Presentation du framework symfony
Presentation du framework symfonyPresentation du framework symfony
Presentation du framework 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
 
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
 
Symfony3 overview
Symfony3 overviewSymfony3 overview
Symfony3 overviewSymfonyMu
 
Symfony2 Presentation
Symfony2 PresentationSymfony2 Presentation
Symfony2 Presentationyllieth
 
Atelier Symfony2- Introduction
Atelier Symfony2- IntroductionAtelier Symfony2- Introduction
Atelier Symfony2- IntroductionMarwa OUNALLI
 
Introduction à Symfony2
Introduction à Symfony2Introduction à Symfony2
Introduction à Symfony2Hugo 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
 
Symfony 2 : chapitre 2 - Les vues en Twig
Symfony 2 : chapitre 2 - Les vues en TwigSymfony 2 : chapitre 2 - Les vues en Twig
Symfony 2 : chapitre 2 - Les vues en TwigAbdelkader Rhouati
 
Presentation Symfony
Presentation SymfonyPresentation Symfony
Presentation SymfonyJeremy Gachet
 
Formation Symfony2 par KNP Labs
Formation Symfony2 par KNP LabsFormation Symfony2 par KNP Labs
Formation Symfony2 par KNP LabsKNP Labs
 
Presentation Symfony2
Presentation Symfony2Presentation Symfony2
Presentation Symfony2Ahmed ABATAL
 
Présentation de symfony - Human talks aux docks le 8 juillet 2014
Présentation de symfony - Human talks aux docks le 8 juillet 2014Présentation de symfony - Human talks aux docks le 8 juillet 2014
Présentation de symfony - Human talks aux docks le 8 juillet 2014Tony Galmiche
 
Soutenance Zend Framework vs Symfony
Soutenance Zend Framework vs SymfonySoutenance Zend Framework vs Symfony
Soutenance Zend Framework vs SymfonyVincent Composieux
 
Bonnes pratiques de developpement en PHP
Bonnes pratiques de developpement en PHPBonnes pratiques de developpement en PHP
Bonnes pratiques de developpement en PHPPascal MARTIN
 
PHP Composer : Pourquoi ? Comment ? Et plus ...
PHP Composer : Pourquoi ? Comment ? Et plus ...PHP Composer : Pourquoi ? Comment ? Et plus ...
PHP Composer : Pourquoi ? Comment ? Et plus ...Romain Cambien
 
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
 
Symfony 2 : chapitre 4 - Les services et les formulaires
Symfony 2 : chapitre 4 - Les services et les formulairesSymfony 2 : chapitre 4 - Les services et les formulaires
Symfony 2 : chapitre 4 - Les services et les formulairesAbdelkader Rhouati
 

Tendances (20)

Presentation du framework symfony
Presentation du framework symfonyPresentation du framework symfony
Presentation du framework symfony
 
Symfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesSymfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiques
 
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
 
Symfony3 overview
Symfony3 overviewSymfony3 overview
Symfony3 overview
 
Symfony2 Presentation
Symfony2 PresentationSymfony2 Presentation
Symfony2 Presentation
 
Atelier Symfony2- Introduction
Atelier Symfony2- IntroductionAtelier Symfony2- Introduction
Atelier Symfony2- Introduction
 
Introduction à Symfony2
Introduction à Symfony2Introduction à Symfony2
Introduction à Symfony2
 
Utiliser le Zend Framework avec Symfony
Utiliser le Zend Framework avec SymfonyUtiliser le Zend Framework avec Symfony
Utiliser le Zend Framework avec Symfony
 
Symfony 2 : chapitre 2 - Les vues en Twig
Symfony 2 : chapitre 2 - Les vues en TwigSymfony 2 : chapitre 2 - Les vues en Twig
Symfony 2 : chapitre 2 - Les vues en Twig
 
Presentation Symfony
Presentation SymfonyPresentation Symfony
Presentation Symfony
 
Formation Symfony2 par KNP Labs
Formation Symfony2 par KNP LabsFormation Symfony2 par KNP Labs
Formation Symfony2 par KNP Labs
 
Presentation Symfony2
Presentation Symfony2Presentation Symfony2
Presentation Symfony2
 
Présentation de symfony - Human talks aux docks le 8 juillet 2014
Présentation de symfony - Human talks aux docks le 8 juillet 2014Présentation de symfony - Human talks aux docks le 8 juillet 2014
Présentation de symfony - Human talks aux docks le 8 juillet 2014
 
Symfony 2 et le Web
Symfony 2 et le WebSymfony 2 et le Web
Symfony 2 et le Web
 
Soutenance Zend Framework vs Symfony
Soutenance Zend Framework vs SymfonySoutenance Zend Framework vs Symfony
Soutenance Zend Framework vs Symfony
 
PHP5 et Zend Framework
PHP5 et Zend FrameworkPHP5 et Zend Framework
PHP5 et Zend Framework
 
Bonnes pratiques de developpement en PHP
Bonnes pratiques de developpement en PHPBonnes pratiques de developpement en PHP
Bonnes pratiques de developpement en PHP
 
PHP Composer : Pourquoi ? Comment ? Et plus ...
PHP Composer : Pourquoi ? Comment ? Et plus ...PHP Composer : Pourquoi ? Comment ? Et plus ...
PHP Composer : Pourquoi ? Comment ? Et plus ...
 
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
 
Symfony 2 : chapitre 4 - Les services et les formulaires
Symfony 2 : chapitre 4 - Les services et les formulairesSymfony 2 : chapitre 4 - Les services et les formulaires
Symfony 2 : chapitre 4 - Les services et les formulaires
 

En vedette

Support de cours Dolibarr crm debutant hodei
Support de cours Dolibarr crm debutant hodeiSupport de cours Dolibarr crm debutant hodei
Support de cours Dolibarr crm debutant hodeiFranck Patissier
 
Présentation de PHP 5.4 [FR]
Présentation de PHP 5.4 [FR]Présentation de PHP 5.4 [FR]
Présentation de PHP 5.4 [FR]Wixiweb
 
script site e-commerce -php
script site e-commerce -php script site e-commerce -php
script site e-commerce -php Yassine Badri
 
Intégration Continue PHP avec Jenkins CI
Intégration Continue PHP avec Jenkins CIIntégration Continue PHP avec Jenkins CI
Intégration Continue PHP avec Jenkins CIHugo Hamon
 
E commerce - solutions techniques
E commerce - solutions techniquesE commerce - solutions techniques
E commerce - solutions techniquesJérôme Chambard
 
Un exemple élémentaire d'application MVC en PHP
Un exemple élémentaire d'application MVC en PHPUn exemple élémentaire d'application MVC en PHP
Un exemple élémentaire d'application MVC en PHPKristen Le Liboux
 
Alphorm.com Support de la formation JavaScript les fondamentaux
Alphorm.com Support de la formation JavaScript les fondamentauxAlphorm.com Support de la formation JavaScript les fondamentaux
Alphorm.com Support de la formation JavaScript les fondamentauxAlphorm
 
Alphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQLAlphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQLAlphorm
 
Alphorm.com Formation WordPress 4
Alphorm.com Formation WordPress 4 Alphorm.com Formation WordPress 4
Alphorm.com Formation WordPress 4 Alphorm
 
Comment réaliser une bonne application mobile de marque ?
Comment réaliser une bonne application mobile de marque ?Comment réaliser une bonne application mobile de marque ?
Comment réaliser une bonne application mobile de marque ?Clément Bouchet
 
Cours 'E-Commerce' - partie 1
Cours 'E-Commerce' - partie 1Cours 'E-Commerce' - partie 1
Cours 'E-Commerce' - partie 1Retis be
 

En vedette (16)

Support de cours Dolibarr crm debutant hodei
Support de cours Dolibarr crm debutant hodeiSupport de cours Dolibarr crm debutant hodei
Support de cours Dolibarr crm debutant hodei
 
Présentation de PHP 5.4 [FR]
Présentation de PHP 5.4 [FR]Présentation de PHP 5.4 [FR]
Présentation de PHP 5.4 [FR]
 
Presentation symfony
Presentation symfonyPresentation symfony
Presentation symfony
 
Tutoriel java
Tutoriel javaTutoriel java
Tutoriel java
 
Php & My Sql
Php & My SqlPhp & My Sql
Php & My Sql
 
script site e-commerce -php
script site e-commerce -php script site e-commerce -php
script site e-commerce -php
 
Intégration Continue PHP avec Jenkins CI
Intégration Continue PHP avec Jenkins CIIntégration Continue PHP avec Jenkins CI
Intégration Continue PHP avec Jenkins CI
 
E commerce - solutions techniques
E commerce - solutions techniquesE commerce - solutions techniques
E commerce - solutions techniques
 
Développement d'un site web de E-Commerce avec PHP (Première Partie)
Développement d'un site web de E-Commerce avec PHP (Première Partie)Développement d'un site web de E-Commerce avec PHP (Première Partie)
Développement d'un site web de E-Commerce avec PHP (Première Partie)
 
Un exemple élémentaire d'application MVC en PHP
Un exemple élémentaire d'application MVC en PHPUn exemple élémentaire d'application MVC en PHP
Un exemple élémentaire d'application MVC en PHP
 
Alphorm.com Support de la formation JavaScript les fondamentaux
Alphorm.com Support de la formation JavaScript les fondamentauxAlphorm.com Support de la formation JavaScript les fondamentaux
Alphorm.com Support de la formation JavaScript les fondamentaux
 
Alphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQLAlphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQL
 
Php
PhpPhp
Php
 
Alphorm.com Formation WordPress 4
Alphorm.com Formation WordPress 4 Alphorm.com Formation WordPress 4
Alphorm.com Formation WordPress 4
 
Comment réaliser une bonne application mobile de marque ?
Comment réaliser une bonne application mobile de marque ?Comment réaliser une bonne application mobile de marque ?
Comment réaliser une bonne application mobile de marque ?
 
Cours 'E-Commerce' - partie 1
Cours 'E-Commerce' - partie 1Cours 'E-Commerce' - partie 1
Cours 'E-Commerce' - partie 1
 

Similaire à Une application en deux heure - PHP Québec Janvier 2009

Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009
Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009
Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009Philippe Gamache
 
À La découverte de flow3 - t3con12
À La découverte de flow3 -  t3con12À La découverte de flow3 -  t3con12
À La découverte de flow3 - t3con12mguermazi
 
Symfony et eZ Publish: embarquement immédiat - talk at Symfony Live Paris
Symfony et eZ Publish: embarquement immédiat - talk at Symfony Live ParisSymfony et eZ Publish: embarquement immédiat - talk at Symfony Live Paris
Symfony et eZ Publish: embarquement immédiat - talk at Symfony Live ParisNicolas Pastorino
 
08 jus 20101123_cae_linux_presentation
08 jus 20101123_cae_linux_presentation08 jus 20101123_cae_linux_presentation
08 jus 20101123_cae_linux_presentationOpenCascade
 
SfPot Lille 07/2015 - Utiliser Symfony sur des environnements Heroku-like
SfPot Lille 07/2015 - Utiliser Symfony sur des environnements Heroku-likeSfPot Lille 07/2015 - Utiliser Symfony sur des environnements Heroku-like
SfPot Lille 07/2015 - Utiliser Symfony sur des environnements Heroku-likeTristan Maindron
 
Drupal & Symfony2
Drupal & Symfony2Drupal & Symfony2
Drupal & Symfony2th0masr
 
Cloud foundry intro with groovy
Cloud foundry intro with groovyCloud foundry intro with groovy
Cloud foundry intro with groovyGuillaume Laforge
 
Presentation de nagios mohamed bouhamed
Presentation de nagios mohamed bouhamedPresentation de nagios mohamed bouhamed
Presentation de nagios mohamed bouhamedTECOS
 
Gestion des dépendances dans un projet PHP - Forum PHP 2012
Gestion des dépendances dans un projet PHP - Forum PHP 2012Gestion des dépendances dans un projet PHP - Forum PHP 2012
Gestion des dépendances dans un projet PHP - Forum PHP 2012Jean-Marc Fontaine
 
20170222 zimbra et-l'industrialisation-v2
20170222 zimbra et-l'industrialisation-v220170222 zimbra et-l'industrialisation-v2
20170222 zimbra et-l'industrialisation-v2Cloud Temple
 
Présentation de RMI Java
Présentation de RMI JavaPrésentation de RMI Java
Présentation de RMI JavaZakaria Bouazza
 
Gestion des dépendances dans un projet PHP - RMLL 2012
Gestion des dépendances dans un projet PHP - RMLL 2012Gestion des dépendances dans un projet PHP - RMLL 2012
Gestion des dépendances dans un projet PHP - RMLL 2012Jean-Marc Fontaine
 
Alphorm.com Formation Le langage Ruby
Alphorm.com Formation Le langage RubyAlphorm.com Formation Le langage Ruby
Alphorm.com Formation Le langage RubyAlphorm
 
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
 
Introduction à Docker et utilisation en production /Digital apéro Besançon [1...
Introduction à Docker et utilisation en production /Digital apéro Besançon [1...Introduction à Docker et utilisation en production /Digital apéro Besançon [1...
Introduction à Docker et utilisation en production /Digital apéro Besançon [1...Silicon Comté
 

Similaire à Une application en deux heure - PHP Québec Janvier 2009 (20)

Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009
Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009
Laboratoire sécurité : audit de code PHP - Conférence PHP Québec 2009
 
À La découverte de flow3 - t3con12
À La découverte de flow3 -  t3con12À La découverte de flow3 -  t3con12
À La découverte de flow3 - t3con12
 
Sentry
SentrySentry
Sentry
 
Symfony et eZ Publish: embarquement immédiat - talk at Symfony Live Paris
Symfony et eZ Publish: embarquement immédiat - talk at Symfony Live ParisSymfony et eZ Publish: embarquement immédiat - talk at Symfony Live Paris
Symfony et eZ Publish: embarquement immédiat - talk at Symfony Live Paris
 
08 jus 20101123_cae_linux_presentation
08 jus 20101123_cae_linux_presentation08 jus 20101123_cae_linux_presentation
08 jus 20101123_cae_linux_presentation
 
SfPot Lille 07/2015 - Utiliser Symfony sur des environnements Heroku-like
SfPot Lille 07/2015 - Utiliser Symfony sur des environnements Heroku-likeSfPot Lille 07/2015 - Utiliser Symfony sur des environnements Heroku-like
SfPot Lille 07/2015 - Utiliser Symfony sur des environnements Heroku-like
 
Drupal & Symfony2
Drupal & Symfony2Drupal & Symfony2
Drupal & Symfony2
 
Herokup2
Herokup2Herokup2
Herokup2
 
Cucumber Ecosystem Presentation
Cucumber Ecosystem PresentationCucumber Ecosystem Presentation
Cucumber Ecosystem Presentation
 
Cloud foundry intro with groovy
Cloud foundry intro with groovyCloud foundry intro with groovy
Cloud foundry intro with groovy
 
Presentation de nagios mohamed bouhamed
Presentation de nagios mohamed bouhamedPresentation de nagios mohamed bouhamed
Presentation de nagios mohamed bouhamed
 
Gestion des dépendances dans un projet PHP - Forum PHP 2012
Gestion des dépendances dans un projet PHP - Forum PHP 2012Gestion des dépendances dans un projet PHP - Forum PHP 2012
Gestion des dépendances dans un projet PHP - Forum PHP 2012
 
20170222 zimbra et-l'industrialisation-v2
20170222 zimbra et-l'industrialisation-v220170222 zimbra et-l'industrialisation-v2
20170222 zimbra et-l'industrialisation-v2
 
Présentation de RMI Java
Présentation de RMI JavaPrésentation de RMI Java
Présentation de RMI Java
 
Playing With PHP 5.3
Playing With PHP 5.3Playing With PHP 5.3
Playing With PHP 5.3
 
Gestion des dépendances dans un projet PHP - RMLL 2012
Gestion des dépendances dans un projet PHP - RMLL 2012Gestion des dépendances dans un projet PHP - RMLL 2012
Gestion des dépendances dans un projet PHP - RMLL 2012
 
Alphorm.com Formation Le langage Ruby
Alphorm.com Formation Le langage RubyAlphorm.com Formation Le langage Ruby
Alphorm.com Formation Le langage Ruby
 
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
 
Introduction à Docker et utilisation en production /Digital apéro Besançon [1...
Introduction à Docker et utilisation en production /Digital apéro Besançon [1...Introduction à Docker et utilisation en production /Digital apéro Besançon [1...
Introduction à Docker et utilisation en production /Digital apéro Besançon [1...
 
Installation open erp
Installation open erpInstallation open erp
Installation open erp
 

Plus de Philippe Gamache

Cryptographie 101 Pour les programmeurs (PHP)
Cryptographie 101 Pour les programmeurs (PHP)Cryptographie 101 Pour les programmeurs (PHP)
Cryptographie 101 Pour les programmeurs (PHP)Philippe Gamache
 
Content-Security-Policy 2018.0
Content-Security-Policy 2018.0Content-Security-Policy 2018.0
Content-Security-Policy 2018.0Philippe Gamache
 
Multi Factor Authetification - ZendCon 2017
Multi Factor Authetification - ZendCon 2017Multi Factor Authetification - ZendCon 2017
Multi Factor Authetification - ZendCon 2017Philippe Gamache
 
Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Philippe Gamache
 
Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017Philippe Gamache
 
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017 OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017 Philippe Gamache
 
Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017Philippe Gamache
 
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017Philippe Gamache
 
Kaizen ou l'amélioration continue
Kaizen ou l'amélioration continueKaizen ou l'amélioration continue
Kaizen ou l'amélioration continuePhilippe Gamache
 
Entreprise Security API - OWASP Montreal
Entreprise Security API - OWASP MontrealEntreprise Security API - OWASP Montreal
Entreprise Security API - OWASP MontrealPhilippe Gamache
 
Entreprise Security API - ConFoo 2011
Entreprise Security API - ConFoo 2011Entreprise Security API - ConFoo 2011
Entreprise Security API - ConFoo 2011Philippe Gamache
 
Strong authetification - ConFoo 2011
Strong authetification - ConFoo 2011Strong authetification - ConFoo 2011
Strong authetification - ConFoo 2011Philippe Gamache
 
Une application en une heure avec symfony - Collège de Mainsonneuve
Une application en une heure avec symfony - Collège de MainsonneuveUne application en une heure avec symfony - Collège de Mainsonneuve
Une application en une heure avec symfony - Collège de MainsonneuvePhilippe Gamache
 
One hour application - PHP Quebec Conference 2009
One hour application - PHP Quebec Conference 2009One hour application - PHP Quebec Conference 2009
One hour application - PHP Quebec Conference 2009Philippe Gamache
 
Audit de code PHP - PHP Code Audit - HackFest.ca 2009
Audit de code PHP - PHP Code Audit - HackFest.ca 2009Audit de code PHP - PHP Code Audit - HackFest.ca 2009
Audit de code PHP - PHP Code Audit - HackFest.ca 2009Philippe Gamache
 
Auditing and securing PHP applications - FRHACK 2009
Auditing and securing PHP applications - FRHACK 2009Auditing and securing PHP applications - FRHACK 2009
Auditing and securing PHP applications - FRHACK 2009Philippe Gamache
 

Plus de Philippe Gamache (17)

Cryptographie 101 Pour les programmeurs (PHP)
Cryptographie 101 Pour les programmeurs (PHP)Cryptographie 101 Pour les programmeurs (PHP)
Cryptographie 101 Pour les programmeurs (PHP)
 
Content-Security-Policy 2018.0
Content-Security-Policy 2018.0Content-Security-Policy 2018.0
Content-Security-Policy 2018.0
 
Mentor et votre équipe
Mentor et votre équipeMentor et votre équipe
Mentor et votre équipe
 
Multi Factor Authetification - ZendCon 2017
Multi Factor Authetification - ZendCon 2017Multi Factor Authetification - ZendCon 2017
Multi Factor Authetification - ZendCon 2017
 
Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017
 
Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017
 
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017 OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
 
Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017
 
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017
OWASP Top 10 Proactive Controls 2016 - PHP Québec August 2017
 
Kaizen ou l'amélioration continue
Kaizen ou l'amélioration continueKaizen ou l'amélioration continue
Kaizen ou l'amélioration continue
 
Entreprise Security API - OWASP Montreal
Entreprise Security API - OWASP MontrealEntreprise Security API - OWASP Montreal
Entreprise Security API - OWASP Montreal
 
Entreprise Security API - ConFoo 2011
Entreprise Security API - ConFoo 2011Entreprise Security API - ConFoo 2011
Entreprise Security API - ConFoo 2011
 
Strong authetification - ConFoo 2011
Strong authetification - ConFoo 2011Strong authetification - ConFoo 2011
Strong authetification - ConFoo 2011
 
Une application en une heure avec symfony - Collège de Mainsonneuve
Une application en une heure avec symfony - Collège de MainsonneuveUne application en une heure avec symfony - Collège de Mainsonneuve
Une application en une heure avec symfony - Collège de Mainsonneuve
 
One hour application - PHP Quebec Conference 2009
One hour application - PHP Quebec Conference 2009One hour application - PHP Quebec Conference 2009
One hour application - PHP Quebec Conference 2009
 
Audit de code PHP - PHP Code Audit - HackFest.ca 2009
Audit de code PHP - PHP Code Audit - HackFest.ca 2009Audit de code PHP - PHP Code Audit - HackFest.ca 2009
Audit de code PHP - PHP Code Audit - HackFest.ca 2009
 
Auditing and securing PHP applications - FRHACK 2009
Auditing and securing PHP applications - FRHACK 2009Auditing and securing PHP applications - FRHACK 2009
Auditing and securing PHP applications - FRHACK 2009
 

Une application en deux heure - PHP Québec Janvier 2009

  • 1. Une application en deux heures Avec Symfony vendredi 13 novembre 2009 1
  • 2. Objectif • Présenter symfony d’une façon originale • Faire une application en une heure vendredi 13 novembre 2009 2
  • 3. Qui suis-je? • Philippe Gamache •Expert en sécurité PHP chez Sensio Labs •Auteur du livre « Sécurité PHP 5 et MySQL » avec Damien Seguy, chez Eyrolles •http://www.phportail.net •http://lapageamelkor.org •naheulbeukauquebec.ca vendredi 13 novembre 2009 3
  • 4. Des questions? ? N’attendez pas à la fin vendredi 13 novembre 2009 4
  • 5. L’application • Blogue • Commentaires • URLs propres vendredi 13 novembre 2009 5
  • 6. symfony • Cadre d’application WEB en PHP • Basé sur : • 10 ans d’expérience chez Sensio • D’autres logiciels libres existants • Licence MIT • Documentation est libre • Grande communauté vendredi 13 novembre 2009 6
  • 7. symfony • Créer pour: • Sites web professionnels • Besoins complexes • Environnements exigeants • Développement rapide vendredi 13 novembre 2009 7
  • 8. Installer symfony http://www.symfony-project.org/installation • Source • Bac à sable • Installation via PEAR • Installation via SVN • Installation Linux (Debian et SUSE) vendredi 13 novembre 2009 8
  • 9. Installation PEAR pear channel-discover pear.symfony-project.com pear install symfony/symfony-1.2.1 vendredi 13 novembre 2009 9
  • 10. Création du projet • Créer le répertoire du projet $ mkdir -p blogue $ cd blogue • Vérifier la version de symfony $ symfony -V • Créer un projet $ symfony generate:project blogue vendredi 13 novembre 2009 10
  • 11. Création du projet • Créer une application $ symfony generate:app / --escaping-strategy=on / --csrf-secret=UniqueSecret / frontend • Ajuster votre serveur web vendredi 13 novembre 2009 11
  • 13. Activation de sfDoctrine // config/ProjectConfiguration.class.php public function setup() { $this->enableAllPluginsExcept( array('sfPropelPlugin', 'sfCompat10Plugin')); } vendredi 13 novembre 2009 13
  • 14. La base de données • Créer la base de données $ mysqladmin -uroot -pmYsEcret / create jobeet • Configurer le projet $ symfony configure:database / --name=doctrine / --class=sfDoctrineDatabase / "mysql:host=localhost;dbname=blogue" / root mYsEcret • Effacer la connexion de Propel vendredi 13 novembre 2009 14
  • 15. Plugiciels • Installer les plugiciels http://www.symfony-project.org/plugins/ • sfDoctrineGuardPlugin $ symfony plugin:install / sfDoctrineGuardPlugin / --release=3.0.0 vendredi 13 novembre 2009 15
  • 16. Le modèle vendredi 13 novembre 2009 16
  • 17. Le schéma # config/doctrine/schema.yml actAs: [Timestampable] BlogPost: actAs: Timestampable: ~ Sluggable: fields: [title] BlogComment: unique: true columns: columns: blog_post_id: integer is_published: author_name: string(255) type: boolean author_email: string(255) default: false author_url: string(255) allow_comments: content: string(5000) type: boolean relations: default: true BlogPost: author_id: integer(4) local: blog_post_id title: string(255) foreign: id content: string(500000) type: one published_at: date foreignAlias: Comments relations: Author: class: sfGuardUser local: author_id foreign: id type: one vendredi 13 novembre 2009 17
  • 18. Données de tests # data/fixtures/fixtures.yml sfGuardUser: philippeg: username: Philippe Gamache password: password is_super_admin: true sfGuardPermission: sgp_admin: name: admin description: Administrator permission sfGuardGroup: sgg_admin: name: admin description: Administrator group sfGuardGroupPermission: sggp_admin: sfGuardGroup: sgg_admin sfGuardPermission: sgp_admin sfGuardUserGroup: sgug_admin: sfGuardGroup: sgg_admin sfGuardUser: philippeg vendredi 13 novembre 2009 18
  • 19. Données de tests BlogPost: post_1: Author: philippeg title: Lorem ipsum dolor sit amet content: | <p>Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...</p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do...</p> is_published: true published_at: 09-01-07 post_2: Author: philippeg title: Ut enim ad minim veniam content: | <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p> <p>Duis aute irure dolor in reprehenderit in voluptate velit esse...</p> is_published: true published_at: 09-01-07 post_3: Author: philippeg title: Duis aute irure dolor in reprehenderit in voluptate content: | <p>Duis aute irure dolor in reprehenderit in voluptate velit esse...</p> <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p> is_published: true published_at: 09-01-07 ... vendredi 13 novembre 2009 19
  • 20. Données de tests BlogComment: comment_1: BlogPost: post_1 author_name: lorem content: Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. comment_2: BlogPost: post_1 author_name: elit content: Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. comment_3: BlogPost: post_3 author_name: aute content: Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. comment_4: BlogPost: post_3 author_name: aute content: ESunt in culpa qui officia deserunt mollit anim id est laborum. vendredi 13 novembre 2009 20
  • 21. Création du code • Utiliser le générateur de code $ symfony doctrine:generate-crud / --with-show frontend post BlogPost • Effacer les actions inutiles • executeNew() • executeEdit() • executeUpdate() • executeDelete() • processForm() vendredi 13 novembre 2009 21
  • 22. Création du code • Effacer les fichiers inutiles • templates/_form.php • templates/editSuccess.php • templates/newSuccess.php • Effacer les liens vers les autres fonctions vendredi 13 novembre 2009 22
  • 23. Création du code • Modifier templates/indexSuccess.php <?php foreach ($blog_post_list as $blog_post): ?> <h2><?php echo link_to($blog_post->gettitle(), '@post_show?slug=' . $blog_post->getslug()) ?></h2> <div>Par <?php echo $blog_post->getAuthor() ?> le <?php echo $blog_post->getpublished_at() ?></div> <p> <?php echo $blog_post->getContentSuccess() ?> </p> <p><?php echo link_to('Voir plus...', '@post_show?slug=' . $blog_post- >getslug()) ?></p> <br /><br /> <?php endforeach; ?> vendredi 13 novembre 2009 23
  • 24. Création du code • Modifier templates/showSuccess.php <h2><?php echo $blog_post->gettitle() ?></h2> <div>Par <?php echo $blog_post->getAuthor() ?> le <?php echo $blog_post- >getpublished_at() ?></div> <p><?php echo nl2br($blog_post->getcontent()) ?></p> <hr /><br /><br /> <?php echo link_to('List', '@homepage') ?> vendredi 13 novembre 2009 24
  • 25. Création du code • Ajouter au templates/layout.php <div id="header"> <h1><?php echo link_to('Mon Blogue', '@homepage') ?></h1> </div> <div id="content"> <?php echo $sf_data->getRaw('sf_content') ?> </div> <div id="footer"></div> • Ajouter web/css/blog.css • Modifier apps/frontend/config/view.yml vendredi 13 novembre 2009 25
  • 26. Création du code • Modifier actions.class.php public function executeIndex(sfWebRequest $request) { $this->blog_post_list = Doctrine::getTable('BlogPost') ->createQuery('a') ->where('a.is_published = 1') ->execute(); } public function executeShow(sfWebRequest $request) { $this->blog_post = Doctrine::getTable('BlogPost') ->findOneBySlug($request->getParameter('slug')); $this->forward404Unless($this->blog_post); } vendredi 13 novembre 2009 26
  • 27. Création du code • Modifier BlogPost.class.php public function getContentSummary() { $out = explode('<', nl2br(substr($this->getcontent(), 0, 500))); return $out[0] . '...'; } • Ajouter à routing.yml post_show: url: /:slug param: { module: post, action: show } vendredi 13 novembre 2009 27
  • 28. Ajouter les commentaires • Utiliser le générateur de code $ symfony doctrine:generate-crud / frontend comment BlogComment • Copier le code dont vous aurez besoin vendredi 13 novembre 2009 28
  • 29. Ajouter les commentaires • Modifier le code dans actions.class.php public function executeIndex(sfWebRequest $request) { $this->blog_post_list = Doctrine::getTable('BlogPost') ->createQuery('p') ->groupBy('p.published_at, p.id') ->where('p.is_published = 1') ->execute(); } public function executeShow(sfWebRequest $request) { $this->blog_post = Doctrine::getTable('BlogPost') ->findOneBySlug($request->getParameter('slug')); $this->forward404Unless($this->blog_post); $this->form = new BlogCommentForm(); } vendredi 13 novembre 2009 29
  • 30. Ajouter les commentaires • Ajouter le code dans actions.class.php public function executeCreate(sfWebRequest $request) { $this->forward404Unless($request->isMethod('post')); $this->blog_post = Doctrine::getTable('BlogPost') ->findOneBySlug($request->getParameter('slug')); $this->forward404Unless($this->blog_post); $comment = new BlogComment(); $comment->setBlogPost($this->blog_post); $this->form = new BlogCommentForm($comment); $this->processForm($request, $this->form); $this->setTemplate('show'); } vendredi 13 novembre 2009 30
  • 31. Ajouter les commentaires • Ajouter le code dans actions.class.php public function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParameter($form->getName())); if ($form->isValid()) { $blog_comment = $form->save(); $this->redirect('@post_show?slug=' . $request->getParameter('slug')); } } • Ajouter a routing.yml comment: url: /comment/:slug param: { module: post, action: create } vendredi 13 novembre 2009 31
  • 32. Ajouter les commentaires • Modifier templates/showSuccess.php ... <p><?php echo nl2br($blog_post->getcontent()) ?></p> <?php if (count($blog_post->getComments())): ?> <ul id="comments"> <?php foreach ($blog_post->getComments() as $comment): ?> <li class="comments"> <br /> <div class="bold">Poster <?php echo $comment->getcreated_at() ?> par <?php echo $comment->getauthor_name() ?> le </div> <p> <?php echo $comment->getcontent() ?> </p> </li> <?php endforeach; ?> </ul> <?php endif ?> <br /> ... vendredi 13 novembre 2009 32
  • 33. Ajouter les commentaires • Modifier templates/showSuccess.php ... <p class="bold">Ajouter votre commentaire</p> <br /> <?php include_partial('form', array('form' => $form, 'blog_post' => $blog_post)) ?> <hr /><br /><br /> <?php echo link_to('List', '@homepage') ?> vendredi 13 novembre 2009 33
  • 34. Ajouter les commentaires • Modifier templates/indexSuccess.php ... <p> <?php echo $blog_post->getContentSuccess() ?> </p> <p>Commentaire (<?php echo count($blog_post->getComments()) ?>) : <?php echo link_to('Voir plus...', '@post_show?slug=' . $blog_post- >getslug()) ?></p> <br /><br /> <?php endforeach; ?> • Déplacer _form.php vendredi 13 novembre 2009 34
  • 35. Ajouter les commentaires • Modifier templates/_form.php ... <form action="<?php echo url_for('@comment?slug=' . $blog_post->getSlug()) ?>" method="POST"> <?php if (!$form->getObject()->isNew()): ?> <input type="hidden" name="sf_method" value="PUT" /> <?php endif; ?> <table> ... • Garder que • author_name • author_email • author_url • content vendredi 13 novembre 2009 35
  • 36. Ajouter les commentaires • Modifier BlogCommentForm.class.php public function configure() { unset( $this['created_at'], $this['updated_at'], $this['blog_post_id'] ); $this->validatorSchema['author_email'] = new sfValidatorEmail(array('required' => false)); $this->validatorSchema['author_url'] = new sfValidatorUrl(array('required' => false)); $this->widgetSchema->setLabels(array( 'author_email' => 'Votre courriel ', 'author_name' => 'Votre nom ', 'author_url' => 'Site Web ', 'content' => 'Commentaire ', )); } vendredi 13 novembre 2009 36
  • 37. Création du Backend • Créer une application $ symfony generate:app / --escaping-strategy=on / --csrf-secret=UniqueSecret / backend vendredi 13 novembre 2009 37
  • 38. Création du Backend • Créer les modules $ symfony generate:admin / --module=post backend BlogPost $ symfony generate:admin / --module=comment backend / BlogComment vendredi 13 novembre 2009 38
  • 39. Création du Backend • Modifier routing.yml sf_guard_signin: url: /login param: { module: sfGuardAuth, action: signin } sf_guard_signout: url: /logout param: { module: sfGuardAuth, action: signout } sf_guard_password: url: /request_password param: { module: sfGuardAuth, action: password } # default rules homepage: url: / param: { module: post, action: index } vendredi 13 novembre 2009 39
  • 40. Création du Backend • Ajouter au templates/layout.php <div id="header"> <h1><?php echo link_to('Mon Blogue', '@homepage') ?></h1> </div> <div id="menu"> <ul> <li><?php echo link_to('Poste', '@blog_post') ?></li> <li><?php echo link_to('Commentaire', '@blog_comment') ?></li> </ul> </div> <div id="content"> <?php echo $sf_data->getRaw('sf_content') ?> </div> <div id="footer"></div> • Modifier apps/frontend/config/view.yml vendredi 13 novembre 2009 40
  • 41. Création du Backend • Modifier setting.yml ... all: .actions: login_module: sfGuardAuth login_action: signin secure_module: sfGuardAuth secure_action: secure .settings: enabled_modules: [default, sfGuardAuth] ... • Modifier setting.yml default: is_secure: on vendredi 13 novembre 2009 41
  • 42. Création du Backend • Modifier post generator.yml ... config: actions: ~ fields: ~ list: title: Liste de message display: [is_published, author_id, =title, published_at] filter: display: [is_published] form: ~ edit: title: Modifier le message "%%title%%" display: [is_published, author_id, title, content, published_at] new: title: Nouveau message display: [is_published, author_id, title, content, published_at] vendredi 13 novembre 2009 42
  • 43. Création du Backend • Modifier comment generator.yml ... config: actions: ~ _delete: ~ _list: ~ fields: ContentSummary: label: Commentaires list: object_actions: _delete: ~ actions: __: ~ title: Liste des commentaires display: [blog_post_id, =author_name, =ContentSummary] filter: display: [blog_post_id] form: ~ edit: ~ new: ~ vendredi 13 novembre 2009 43
  • 44. Création du Backend • Modifier myUser.class.php class myUser extends sfGuardSecurityUser { } vendredi 13 novembre 2009 44
  • 45. Pour aller plus loins • Ajouter étiquettes (tags) • Ajouter un mini-calendrier • Mettre les billets par mois • Ajouter recherche par date • Ajouter des flux de données (RSS, ATOM) via sfFeed2plugins vendredi 13 novembre 2009 45
  • 46. Questions? philippe.gamache@symfony-project.com info@ph-il.ca http://www.symfoy-project.org http://www.phportail.net vendredi 13 novembre 2009 46