The blog of COil: PHP, PEAR, symfony1, Symfony2 & iWeb2.0+

Strangebuzz...?

» Collapse all «

Tag - snippets

     

Friday 6 January 2012

Extending the Symfony2 session

Hi symfonians ! :)

If you are used to symfony1, you probably noticed that you don't have a myUser class to handle the user session. It's generally useful so you don't have to handle directly with session attributes and you can also have shortcuts. Well it's quiet easy to have such a class in Symfony2:
Declare your own session class as the framework level in your app/config.yml config file:


And now create your own mySession class which extends the default Symfony2 session class:


And your done. :)

PS: The class can be stored in another location, I'm not sure which is the best ?
PS2: The service could also be loaded at the Bundle level.

Thursday 12 April 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 démo de mon plugin sfJoomlaBridge)

[php]
<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

[php]
<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]
<?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

Sunday 4 February 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


Sunday 14 January 2007

Multi-sort dans l'admin generator de Symfony

[En] Welcome on my new blog that will mainly talk about PHP, the Symfony framework and web2.0.

[Es] Bienvenido en mi nuevo blog, principalmente hablando sobre PHP, Symfony framework y web2.0.

[Fr] Voilà je me suis décidé à ouvrir mon Blog, non pour raconter ma vie... quoi que ;) ... Mais pour parler essentiellement de programmation, notamment PHP et le framework Symfony dont je suis très friand ces derniers temps. ;) J'ai choisi DotClear pour sa réputation, sa facilité d'utilisation, les thèmes disponibles et les plugins. Je ne suis vraiment pas déçu pour l'instant. C'est propre et clair. J'ai du installer un plugin intégrant Geshi pour la coloration syntaxique PHP.


Présentation

Une petite présentation (vite-fait hein...) je suis COil (devinez-mon prénom ?), j'ai 28 ans... Et je me suis re-mis (**sérieusement**) au PHP et aux technos web depuis 6 mois apres une longue mission à Paris, ça fait du bien. La conception technique de sites web, le php et le webmastering étant vraiment les disciplines que je préfère.


J'espère que vous pourrez trouver ici quelques informations intéressantes à l'occasion. (pas toujours quand même, faut pas pousser...) :o