So this is just a little tip when you need to load your own yaml file.
To load a yaml file you can use sfYamlConfigHandler::parseYaml() ( or sfYaml::load() ). And just after you can also use sfYamlConfigHandler::replaceConstants() to replace constant(s) from Symfony such as %SF_LIB_DIR% (or any other value defined in a yaml config file) in the values you've just loaded from your custom yaml file.
A little exemple:
Tag - symfony
Sunday, May 9 2010
Little tip when you need to load your own yaml file
By eNk` on Sunday, May 9 2010, 16:25 - Symfony
Monday, April 5 2010
Custom sfValidatorFile and sfValidatedFile
By eNk` on Monday, April 5 2010, 10:56 - Symfony
In this post I will show a way to customize the file upload with the forms framework. The forms framework provide the sfWidgetFormInputFile class to display a file input tag and the sfValidatorFile class which is the default class used to validate a file input field. As all validator classes sfValidatorFile check if the field value is ok according to the validation options, but instead of returning a "basic" value such as an integer or a string, this validator will return an instance of sfValidatedFile as a clean value.
Thursday, January 21 2010
Customize Doctrine model builder options
By eNk` on Thursday, January 21 2010, 14:51 - Symfony
This is just a little tip to customize the builder options for the generated model classes (lib/model/). Basically if we define a MyClass class in the schema.yml we will have this:
- MyClass > BaseMyClass > sfDoctrineRecord > Doctrine_Record > ...
- MyClassTable > Doctrine_Table > ...
Thursday, November 26 2009
How to create a custom Doctrine behavior
By eNk` on Thursday, November 26 2009, 15:19 - Symfony
So all is in the tittle ^^, in this post I will speak about a way to create your own Doctrine behavior. I really want to share this because it's the first time I create a behavior and I didn't really find any post about it with some complete exemple with code.
Before starting:
Why behavior could be very useful ? I think this well explained in the Doctrine documentation here ^^.
Why I wrote this post ? The Doctrine documentation contains very good explainations about the way of using temaples but I think it's blur about the way you can link a template and a generator in order to generate some classes on the fly.
Friday, November 13 2009
Advanced filters with numbers for Doctrine. (fr and en)
By Mathieu on Friday, November 13 2009, 13:07 - Symfony
Dernièrement j'ai du filtrer les nombres de façon supérieur ou inférieure sur un champ "prix", je me suis alors rendu compte que les filtres de Symfony avec Doctrine ne permettait pas cela, j'ai donc commençait à chercher une solution en me plongeant dans le code de Symfony, sans vraiment chercher sur internet je l'avoue, mais ça fait parfois du bien de voir comment marche l'outil que l'on utilise tous les jours ;) .
Lately I had to filter some numbers on a price field. The aim was to filter by bigger or smaller than the price value. I realized default Doctrine filters doesn't allow to do that, so I started to search a solution by looking at the Symfony code. I admint I don't really look on the internet to find a solution, but sometimes it's good to look inside the tool we use everyday ;).
Friday, October 16 2009
Add new tasks in your Symfony project
By eNk` on Friday, October 16 2009, 11:10 - Symfony
So for my very first post in english I will talk about how to add a new task in symfony. Task are very useful to handle a lot of data and can be launched manually or placed in a cron job.
I started to create task on a new project, in the past I used to create a batch folder in my symfony project. In this folder I created a symfony.inc.php to load symfony and others php files which use the symfony.inc.php to handle data. So this way of creating task work, but symfony provide the sfBaseTask class so why don't use it ? This class allow you to add task to your symfony project in addition to those provided by the framework.
Monday, August 3 2009
Clear Cache
By eNk` on Monday, August 3 2009, 16:42 - Symfony
Bon il fallait bien le faire, donc le voici. Le mini billet sur notre commande préférée LE "symfony cc".
cache:clear de son nom complet et "cc" pour les intimes et gros flemmard que nous sommes =]. Qui a déjà écris "cache:clear" en entier ? Dénoncez vos collègues, et pour la peine ils devront payer une tournée au prochain sfPot.
Thursday, July 9 2009
Les Criteria c'est trop nul :p
By eNk` on Thursday, July 9 2009, 13:35 - Symfony
Derrière ce titre un peu "trollesque" se cache en fait un petit billet dans lequel nous allons voir comment faire des requêtes avec Propel 1.3 en utilisant directement PDO, donc sans passer par la case Criteria/Criterion, et hydrater les objets correspondant.
Prenons un exemple avec le schéma suivant, dans lequel nous avons des utilisateurs pouvant écrire des posts et faire parti de groupes.
Friday, May 15 2009
SQLSTATE[HY000]: General error: 1005
By Stéphane.p on Friday, May 15 2009, 10:50 - Symfony
SQLSTATE[HY000]: General error: 1005 Can't create table './ma_table/#sql-6d79_2523.frm' (errno: 150). Failing Query: ALTER TABLE table2 ADD FOREIGN KEY (table1) REFERENCES table1(id) ON DELETE SET NULL
Voilà une erreur qui m'est apparue plusieurs fois, assez embêtante lorsqu'on ne connait pas la solution.
Thursday, May 7 2009
Custom validator sous symfony 1.2
By eNk` on Thursday, May 7 2009, 09:25 - Symfony
Dans ce billet nous allons voir comment créer un sfValidator custom utilisable avec le framework de formulaire.
Dans cet exemple nous allons créer un validateur permettant de vérifier si un pseudo est déjà existant dans la base de données. Ce validateur pourra par exemple être utilisé sur un formulaire d'inscription afin de forcer les utilisateurs à choisir un pseudo qui n'existe pas encore.
Commençons par créer une classe PseudoValidator qui hérite de sfValidatorBase, dans laquelle nous allons redéfinir les méthodes configure() et doClean(). La méthode configure() va permettre de définir les options et les messages de notre validateur. La méthode doClean() va quand à elle être utilisée pour valider la valeur du champ.Vous pouvez par exemple créer cette classe dans le répertoire _my_project_/lib/validator.
Tuesday, April 28 2009
Formulaires symfony: Traitement sur la valeur d'un champ à la sauvegarde
By eNk` on Tuesday, April 28 2009, 21:43 - Symfony
Voici une petite astuce permettant d'effectuer un traitement sur la valeur d'un champ lors de la sauvegarde d'un formulaire Doctrine ou Propel.
Imaginons par exemple une classe User avec deux attributs login et password de type string, password que nous allons sauvegarder en MD5 dans notre table user.
Pour enregistrer un utilisateur en base nous allons évidemment utiliser la classe de formulaire correspondant à notre classe User. Il serait donc pratique que lorsque l'on appelle la méthode save() de notre objet UserForm le mot de passe saisi par l'utilisateur dans le champ password soit automatiquement converti en MD5.