The blog of COil : PHP, symfony & Web 2.0

Strangebuzz...?

Réduire au titre / collapse all

03/04/2008

» symfony tutorial : Extending the admin generator

[En] Tutorial content:

  • Creating a plugin with a custom admin generator theme
  • Extending the sfActions class
  • Extending the sfPropelAdminGenerator class


Here is little contribution for the symfony code sprint, a symfony tutorial about the admin generator. :) Do you know about it ? I think it's one of my favourite symfony tool, i have developed several applications with symfony and for 75% of them i have made a custom admin generator theme. And as said in the symfony documentation, the admin generator is very very very powerful. ;)
In this tutorial we will see a concrete example on how to extend it to provide a useful new feature. Witch feature ? Well it was one of the things a customer asked me, "I want to be able to delete several rows at a time with check boxes" ... Ahhhhh indeed, it's not a native feature of the admin generator. So.... let's do it... :)

::: Pre-requisite :::


Well i will not explain here how to install symfony as there are lots of tutorials about this on the symfony website and in the wiki. So i will assume you have a clean symfony installation so you can type the symfony command in cli. I used the 1.0.13 version for this tutorial.

::: Creating and setting a new project :::


:: Creating the new project ::


First we will create the new project that we will call tutorial, create a new folder tutorial and launch the init-project task into it.

symfony init-project tutorial

Now let's create the backend application:

symfony init-app backend

As it is always better to have a submain for our application add the following in you apache httpd.conf file and change it with your own path

## COil symfony tutorial n°1 : Extending the admin generator ##

<VirtualHost *:80>
  ServerName dev.tutorial.com
  DocumentRoot "C:\wamp\www\tutorial\web"
  DirectoryIndex index.php
  Alias /sf "c:\wamp\bin\php\php5.2.5\PEAR\data\symfony\web\sf"
  
  <Directory "C:\wamp\www\tutorial\web">
    AllowOverride All
  </Directory>
</VirtualHost>

Add the sub-domain in you hosts file:

127.0.0.1 dev.tutorial.com

Ok, at this point we should have our "Project created!" page. So Let's try to browse http://dev.tutorial.com/backend_dev.php

tuto1-1


:: The database ::


Create a local database, let's call it tutorial again. (same as the project name)
Modify the database settings in the config/database.yml and config/propel.ini file, your database.yml file should look like this:

all:
  propel:
    class:          sfPropelDatabase
    param:
      dsn:          mysql://root@localhost/tutorial


Now we need a schema, let's take the one of Askeet


Ok now let's try to build the database:

symfony.bat propel-build-all-load backend

Oops, it seems there are some errors. :) As we are quite lazy just delete the password columns and the QuestionTag section of the /datas/fixtures/test_data.yml file.
Let's try again to run the last command. If your are successful you should now have some tables and data in your tutorial database. If not, you probably missed something. ;) At this point we have a valid application with a database, some tables and fixtures. Settings are ok, so can go to the next step.

...

Lire la suite / read all

18/03/2008

» Symfony tip : Registration of plugin routes

[En] Here is a little tip Fabien gave me. I am actually developing a plugin witch has quiet a lot of routes (about 40). Normally you can add the routes with the prependRoute function, like does the sfGuardplugin.

<?php
if (sfConfig::get('app_sf_guard_plugin_routes_register', true) && in_array('sfGuardAuth', sfConfig::get('sf_enabled_modules', array())))
{
  $r = sfRouting::getInstance();
 	
  // preprend our routes
  $r->prependRoute('sf_guard_signin', '/login', array('module' => 'sfGuardAuth', 'action' => 'signin'));
  $r->prependRoute('sf_guard_signout', '/logout', array('module' => 'sfGuardAuth', 'action' => 'signout'));
  $r->prependRoute('sf_guard_password', '/request_password', array('module' => 'sfGuardAuth', 'action' => 'password'));
}
?>


But for each prependRoute call an array_merge is done on all existing routes.

<?php
  /**
   * Adds a new route at the beginning of the current list of routes.
   *
   * @see connect
   */
  public function prependRoute($name, $route, $default = array(), $requirements = array())
  {
    $routes = $this->routes;
    $this->routes = array();
    $newroutes = $this->connect($name, $route, $default, $requirements);
    $this->routes = array_merge($newroutes, $routes);
 
    return $this->routes;
  }
?>


So the tip here is to save all routes, clear them, add the routes of the plugin and then append the saved routes. Witch can be done like this:

<?php
  // Save and clear all routes
  $r = sfRouting::getInstance();
  $routes = $r->getRoutes();
  $r->clearRoutes();
  
  // Plugin home
  $r->connect('plugin_home', '/my_super_plugin/homepage', array(
    'module' => 'my_plugin_module', 
    'action' => 'my_plugin_action',
    'additional_parameter'   => 1
    ));
 
  // Another route
  $r->connect('plugin_home', '/my_super_plugin/section1', array(
    'module' => 'my_plugin_module', 
    'action' => 'my_plugin_action_section1',
    'additional_parameter'   => 2
    ));
 
  // ... other routes
 
  // Then merge new routes with the saved one
  $r->setRoutes($r->getRoutes() + $routes);
?>


That's it. :) Of course it is always better to have all routes of the application in the routing.yml but in my case it was not possible.

02/03/2008

» sfLightboxPlugin 1.0.6

[En] New version with the last version of lightbox (2.03.3) + new helpers. You can check the demo here on my blog.

  • Updated lightbox library to v2.03.3
  • 3 new helpers (light_image_text, light_slide_image, light_slide_text)
  • New parameter for images slideshows to allow to display images as a html list (li..)
  • Slideshow navigation with the keyboard (left, right, ESC)


Thanks for your feedback ! Enjoy. :)



[Fr] Nouvelle version incluant la dernière version de lightbox (2.03.3) et quelques nouveaux helpers. Vous pouvez visualiser la demo ici sur mon blog.

  • Mise à jour de la librairie lightbox pour la version v2.03.3
  • 3 nouveaux helpers (light_image_text, light_slide_image, light_slide_text)
  • Nouveau paramètre pour les slideshows pour afficher les images comme une liste html (li..)
  • Navigation dans le slideshow à l'aide du clavier (gauche, droite, ESC)


Merci pour votre feedback ! Enjoy. :)

sfLightboxPlugin 1.0.6

12/06/2007

» Plugins, plugins and (sf) plugins

[EN] Translation coming soon (edit 19/07: too lazy to do the translation)

[FR] Pas mal de mouvements ces derniers temps dans la section, on compte pas moins de 80 plugins désormais et on se rapproche de la barre fatidique des 100, c'est vraiment excellent pour le framework et lui donne une richesse certaine. On y trouve vraiment de tout, de la série de plugin sur propel qui permettent d'ajouter à cet ORM des fonctionnalités comme l'audit d'objet, la gestion d'arbre... aux plugins plus farfelus qui permettent de gérer des smileys ou qui permettent l'intégration de librairies javascript externes, ou encore qui permettent de s'interfacer avec d'autres applications PHP (sfGallery2Plugin...) Le mieux étant encore d'aller sur le wiki pour dénicher ceux qui pourront vous être utiles... Quant à mes plugins, ils se portent plutôt bien !

  • sfLightboxPlugin en est à la version 1.0.5, la prochaine publication 1.1.0 sera faite par Demental et incluera donc comme le numéro de version le laisse entendre, de nouvelles fonctionnalités. Stay tuned ! ;)
  • sfTCPDFPlugin à été mis à jour par fred, qui a corrigé les bugs, rendu le plugin customisable, corrigé et mis à jour l'exemple complet de la librairie TCPDF. C'est vraiment cool de voir son travail repris, amélioré et publié par quelqu'un d'autre. Mais c'est le principe même de l'open source n'est-ce pas ? :)
  • sfJoomlaPlugin lui au contraire est en train de tomber aux oubliettes... Quelques personnes s'y étaient interessé mais depuis plus grand chose, il est vrai que d'interfacer un framework et un CMS aussi "fouilli" ( ;) ) que Joomla reste une idée assez marginale... Enfin il a le mérite d'exister, si ça peut/a pu servir à quelqu'un... :)

19/04/2007

» [Symfony] sfLightboxPlugin v1.0.3 is out

[En] Yet another new version released by Demental
[Fr] Encore une nouvelle version publiée par Demental

Added the ability to call initmodalbox several times. Corrected wrong paths in config.php

12/04/2007

» View template source with Symfony

[En] A little snippet to display the source code of the current main template displayed in a hidden div, the template (here it is a test of the sfGeshi plugin) (1)
[Edit 20/05/07] You can find a demo here (on the demo of the sfJoomlaBridge)

[Fr] Un petit snippet qui permet d'afficher le code source du template courant utilisé dans un div caché. Le template (ici je faisais un test du plugin sfGeshi)
[Edit 20/05/07] Vous pouvez trouver une demo ici (sur la demo de mon plugin sfJoomlaBridge)

<h1>sfGeshiPlugin</h1>
 
<div id="demo">
    <?php $highlighter = new sfGeshi(file_get_contents(myTools::getTemplatePath()), 'php'); ?>
    <?php echo $highlighter->parse_code(); ?>
</div>
 
<?php include_partial('global/view_source_link'); ?>



[En] The view source link template (_view_source_link.php)
[Fr] Ici le code du template permettant d'afficher le lien pour visualiser le code source

<div id="source-content">
    <hr/>
    <?php $highlighter = new sfGeshi(file_get_contents(myTools::getTemplatePath()), 'php'); ?>
    <p>
    <?php echo link_to_function(
      '&raquo; Show source code of this template',
      visual_effect('SlideDown', 'source')
    ); ?>
    </p>
     
    <div id="source" style="display:none">
        <?php echo $highlighter->parse_code(); ?>
        <p>
        <?php echo link_to_function(
          '&raquo; Close source code',
          visual_effect('SlideUp', 'source')
        ); ?>
        </p>
    </div>
</div>



[En] And the function to get the physical path of the template :
[Fr] Et la fonction permettant de récupérer le chemin physique du template principal en cours :

<?php
    public static function getTemplatePath()
    {
        $context = sfContext::getInstance();
        $module   = $context->getModuleDirectory();
        $template = $context->getCurrentViewInstance()->getTemplate();
        return $module. DIRECTORY_SEPARATOR. 'templates'. DIRECTORY_SEPARATOR. $template;
    }
?>



View template source with Symfony example

27/03/2007

» [Symfony] sfLightboxPlugin v1.0.2

[En] This version was released by Demental, it includes some improvments and bug corrections. As usual you can find all instructions on the Symfony wiki.


[Fr] Cette version a été publié par Demental, elle inclue quelques améliorations et corrections de bugs. Comme d'habitude vous pouvez trouver toutes les instructions sur le wiki Symfony.

18/03/2007

» New Symfony plugin : sfTCPDFPlugin

[En] I have released my third plugin, it's a small one that just provides an easy access to the TCPDF library. TCPDF is an extension of FPDF witch allows to create PDF documents. It mainly differs from its father by supporting UTF8 encoding, witch of course is very interesting for Symfony. As usual you can find all installation instructions on the Sf wiki and a demo on this blog.


[Fr] Je viens de publier mon 3eme plugin Symfony, il est trés simple et fournit un accés facilité à la librairie TCPDF. TCPDF est une extension de FPDF qui permet de créer des documents PDF. Elle différe principalement de son père en supportant l'encodage UTF8, ce qui, bien sûr est trés intérressant pour Symfony. Comme d'habitude vous pouvez trouver toutes les instructions d'installation sur le wiki Sf et une demo sur ce blog.

13/03/2007

» sfJoomlaBridge 0.8.0 released

[En] I have just released the 0.8.0 beta version of sfJoomlaBridgePlugin. What's new ?

  • Can handles Symfony forms now (with error handling)
  • Allow standard use of Symfony Ajax helpers
  • New specific filter
  • New helpers to add sf resources dynamically

I have updated the wiki page, the online demo but i still need to modify the tutorial.


[Fr] Je viens juste de publier la version 0.8.0 beta de mon plugin sfJoomlaBridgePlugin. Quoi de neuf au menu ?

  • Permet désormais d'utiliser les formulaires Symfony (avec la gestion d'erreur)
  • Permet d'utiliser les helpers Ajax Symfony
  • Un nouveau filtre pour traiter l'affichage du template
  • Nouveaux helpers pour ajouter dynamiquement les ressources sf dans le template final.

J'ai mis à jour la page wiki , la demo online mais j'ai encore à modifier le tutorial.

10/03/2007

» Brêves de comptoir n°1

[EN] Click here for the english version / see below

[FR] Pas le courage de poster régulièrement donc voici quelques news en vrac :

  • myBlog

J'ai fait quelques ajouts à mon blog pour le fun, notemment les tags des billets, les tags del.icio.us ainsi que mes dernières url, une pub Google (juste pour tester la chose), quelques petites retouches de css, j'ai aussi fait une page dédiée à mes bookmarks del.icio.us avec un gros nuage de tags et mes 50 dernères url postées, trés pratique pour retrouver rapidement ses infos.

Une nouvelle qui est restée assez discréte je trouve, l'entreprise des concepteurs de Symfony, Sensio a fusionnée avec Extreme pour donner 2 nouvelles entités, Extreme Sensio qui propose une offre "360°" pour le web et Sensiolabs dédié à l'open source et notemment au framework Symfony bien sûr. Une trés bonne nouvelle une fois de plus pour la perennité de ce framework. Je leur souhaite evidemment une trés bonne réussite.

Oui je sais ca fait déjà un moment, on l'attendait depuis longtemps et je ne suis pas décu c'est un trés bon cru, en même temps les gros "changements" sont déjà la depuis pas mal de temps. On peut citer par exemple le nouveau sytème de plugin qui est vraiment intéressant pour capitaliser son code, j'ai aussi testé le système intégré de livraison de code, c'est vraiment hyper pratique, on définit les références de son serveur distant, les fichiers à exlcure de la mise à jour, on fait une 1ere simuation, on valide et c'est fini. (voir la commande >symfony sync)

J'ai avancé sur mon plugin, il gère désormais les formulaires et permet d'utiliser les helpers Ajax symfony direcetement à l'intérieur de l'application Joomla. Je devrais livrer cette version 0.8.0 beta courant de semaine prochaine.

  • Antiséche Symfony : les commandes console

J'ai repéré une anti-séche bien sympa sur les commandes Symfony. Vous pouvez la trouver sur le blog d'Andreia, il y a aussi un graphique récapitulatif sur l'intégration de l'ORM Propel dans Symfony.

Lire la suite / read all