The blog of COil : PHP, symfony & Web 2.0

Strangebuzz...?

Réduire au titre / collapse all

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

04/02/2007

» Snippet : Strip comments of propel classes

[En] In Symfony, comments generated by Propel can sometimes be quiet big. With the 0.6.3 version there was no feature to do this. That's why i made this little batch. We could also imagine extend this snippet to remove all the comments off all php files of an application (for production). If you are using 1.0.0 just add in your "config/propel.ini" (1) :


[Fr] Dans Symfony, les commentaires générés par Propel peuvent parfois être assez gros. Avec la version 0.6.3, il n'y a pas de fonctionnalité pour ne pas les créér. C'est pourquoi j'ai fait ce petit batch. On pourrait aussi imaginer d'étendre ce snippet pour supprimer l'ensembles des commentaires des fichiers php d'une application. (en production). Si vous utilisez la 1.0.0, pas besoin de ce batch cette fonctionnalité est désormais incluse, ajouter dans votre "config/propel.ini" :

(1)

 propel.builder.addIncludes = false
 propel.builder.addComments = false


14/01/2007

» Multi-sort dans l'admin generator de Symfony

[En] Here is snippet that i had put on Sf website some time ago, it allows to add a "multi sort" fonctionnality in the admin generator. Indeed, by default, one can sort on only one table column, witch can be quiet annoying with complex datas.

[Fr] Voici un snippet pour Symony que j'avais déposé dans leur application "Snippets", il permet d'ajouter la fonctionnalité "multi-sort" dans l'admin generator. En effet, par défaut on ne peut trier que sur une seule colonne ce qui dans certains cas peut être limitant avec des données complexes.

<?php
    /**
     * Add a sort criteria
     */
    protected function processSort ()
    {
        $sort = $this->getRequestParameter('sort');
        $type = $this->getRequestParameter('type');            
 
        // Register sort                 
        if ($sort) {
            $this->getUser()->setAttribute($sort, $type, 'sf_admin/produits/sort');
        }
    }
?>


La suite du snippet | Full snippet here