[symfony-users] Re: Form validation
Ciao Richtermeister, I wrote the validator as a Callback: ?php /** * Listino form. * * @packageSuperAdmin * @subpackage form * @author Your name here * @versionSVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $ */ class ListinoForm extends BaseListinoForm { public function configure() { $this-widgetSchema['DataInizioValidita'] = new sfWidgetFormI18nDate (array('culture' = 'it_IT', 'month_format' = 'short_name')); $this-validatorSchema-setPostValidator(new sfValidatorCallback (array('callback' = array($this, 'checkSoglie'; } public function checkSoglie($validator, $values) { $trovataSoglia = false; snip if ($values['Importo'.$i] = $values['Importo'.($i - 1)]) { throw new sfValidatorError($validator, Ogni importo deve essere inferiore al precedente. (Importo$i)); return $values; } } return $values; } } and I put it in lib/form/modelForm.class.php. It's form and problem specific, so I'm not going to reuse the logic anywhere in the project. I wonder if this is the right place where to put the code!? Now I'm looking for a way to highlight the wrong fields (with a red border, like the standard validators do) to the user... Stefano On 12 Ago, 20:34, Richtermeister nex...@gmail.com wrote: Hey Stefano, I would write a custom post-validator. A post validator is given the entire data array, so from there you can just loop over the array and see if the values keep increasing.. Hope this helps, Daniel On Aug 12, 8:57 am, Stefano stef...@sancese.com wrote: Hi, I'm developing my first web-application and I'm still RTFM (Reading The Fabulous Manuals), but I need a little help with a form validation. For this application I'm using the Admin Generator. The form contains 5 target fields: T1, T2, T3, T4, T5; every target must be greater than the previous: T1 T2 T3 T4 T5. But only T1 is required while the other targets can be empty. If a target is empty all the next ones must be empty. So: T1= 100, T2= 200, T3=empty, T4=empty, T5=empty is valid, but: T1=100, T2=empty, T3=200, T4=empty, T5=empty is NOT valid. I'm putting some code in lib/form/modelForm.class.php: class ListinoForm extends BaseListinoForm { public function configure() { $this-validatorSchema-setPostValidator(new sfValidatorAnd(array (new sfValidatorSchemaCompare('T1', sfValidatorSchemaCompare::LESS_THAN, 'T2'; } } but I don't know how to test if a field is empty and I'm afraid that the resulting instruction will be very hard to read. Any hint? TIA Stefano --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups symfony users group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: about session handling
Hi, Below is taken from Symfony Chapter 6 http://www.symfony-project.org/book/1_2/06-Inside-the-Controller-Layer#chapter_06_user_session === User Session Symfony automatically manages user sessions and is able to keep persistent data between requests for users. It uses the built-in PHP session-handling mechanisms and enhances them to make them more configurable and easier to use. Accessing the User Session The session object for the current user is accessed in the action with the getUser() method and is an instance of the sfUser class. This class contains a parameter holder that allows you to store any user attribute in it. This data will be available to other requests until the end of the user session, as shown in Listing 6-15. User attributes can store any type of data (strings, arrays, and associative arrays). They can be set for every individual user, even if that user is not identified. Listing 6-15 - The sfUser Object Can Hold Custom User Attributes Existing Across Requests class mymoduleActions extends sfActions { public function executeFirstPage($request) { $nickname = $request-getParameter('nickname'); // Store data in the user session $this-getUser()-setAttribute('nickname', $nickname); } public function executeSecondPage() { // Retrieve data from the user session with a default value $nickname = $this-getUser()-getAttribute('nickname', 'Anonymous Coward'); } }You can store objects in the user session, but it is strongly discouraged. This is because the session object is serialized between requests. When the session is deserialized, the class of the stored objects must already be loaded, and that's not always the case. In addition, there can be stalled objects if you store Propel objects. Like many getters in symfony, the getAttribute() method accepts a second argument, specifying the default value to be used when the attribute is not defined. To check whether an attribute has been defined for a user, use the hasAttribute() method. The attributes are stored in a parameter holder that can be accessed by the getAttributeHolder() method. It allows for easy cleanup of the user attributes with the usual parameter holder methods, as shown in Listing 6-16. Listing 6-16 - Removing Data from the User Session class mymoduleActions extends sfActions { public function executeRemoveNickname() { $this-getUser()-getAttributeHolder()-remove('nickname'); } public function executeCleanup() { $this-getUser()-getAttributeHolder()-clear(); } }The user session attributes are also available in the templates by default via the $sf_user variable, which stores the current sfUser object, as shown in Listing 6-17. Listing 6-17 - Templates Also Have Access to the User Session Attributes p Hello, ?php echo $sf_user-getAttribute('nickname') ? /pIf you need to store information just for the duration of the current request--for instance, to pass information through a chain of action calls--you may prefer the sfRequest class, which also has getAttribute() and setAttribute() methods. Only the attributes of the sfUser object are persistent between requests. On Sat, Aug 15, 2009 at 9:52 AM, sunnyasim...@gmail.com wrote: Can any body give the right technique how to use session handling --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups symfony users group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: about session handling
Can i use some thing like $_SESSION['name']=asim; in symfony On Sat, Aug 15, 2009 at 7:06 PM, DEEPAK BHATIA toreachdee...@gmail.comwrote: Hi, Below is taken from Symfony Chapter 6 http://www.symfony-project.org/book/1_2/06-Inside-the-Controller-Layer#chapter_06_user_session === User Session Symfony automatically manages user sessions and is able to keep persistent data between requests for users. It uses the built-in PHP session-handling mechanisms and enhances them to make them more configurable and easier to use. Accessing the User Session The session object for the current user is accessed in the action with the getUser() method and is an instance of the sfUser class. This class contains a parameter holder that allows you to store any user attribute in it. This data will be available to other requests until the end of the user session, as shown in Listing 6-15. User attributes can store any type of data (strings, arrays, and associative arrays). They can be set for every individual user, even if that user is not identified. Listing 6-15 - The sfUser Object Can Hold Custom User Attributes Existing Across Requests class mymoduleActions extends sfActions { public function executeFirstPage($request) { $nickname = $request-getParameter('nickname'); // Store data in the user session $this-getUser()-setAttribute('nickname', $nickname); } public function executeSecondPage() { // Retrieve data from the user session with a default value $nickname = $this-getUser()-getAttribute('nickname', 'Anonymous Coward'); } }You can store objects in the user session, but it is strongly discouraged. This is because the session object is serialized between requests. When the session is deserialized, the class of the stored objects must already be loaded, and that's not always the case. In addition, there can be stalled objects if you store Propel objects. Like many getters in symfony, the getAttribute() method accepts a second argument, specifying the default value to be used when the attribute is not defined. To check whether an attribute has been defined for a user, use the hasAttribute() method. The attributes are stored in a parameter holder that can be accessed by the getAttributeHolder() method. It allows for easy cleanup of the user attributes with the usual parameter holder methods, as shown in Listing 6-16. Listing 6-16 - Removing Data from the User Session class mymoduleActions extends sfActions { public function executeRemoveNickname() { $this-getUser()-getAttributeHolder()-remove('nickname'); } public function executeCleanup() { $this-getUser()-getAttributeHolder()-clear(); } }The user session attributes are also available in the templates by default via the $sf_user variable, which stores the current sfUser object, as shown in Listing 6-17. Listing 6-17 - Templates Also Have Access to the User Session Attributes p Hello, ?php echo $sf_user-getAttribute('nickname') ? /pIf you need to store information just for the duration of the current request--for instance, to pass information through a chain of action calls--you may prefer the sfRequest class, which also has getAttribute() and setAttribute() methods. Only the attributes of the sfUser object are persistent between requests. On Sat, Aug 15, 2009 at 9:52 AM, sunnyasim...@gmail.com wrote: Can any body give the right technique how to use session handling --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups symfony users group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] I18n + Umlauts: not working without utf8_encode
Hi everybody, I'm desperatly trying to get I18n to work via MySQL, but Umlauts are impossible to retrieve: so echo __(Delete) will bring L?schen. - I'm using Propel. - DB: DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci - trans_unit table: CHARSET=utf8 - propel.ini: propel.database.encoding = utf8 - databases.yml: encoding: utf8 - settings.yml: charset: utf-8 - All my files are utf8 encoded via Eclipse inheritance Now, when I use a generator module to show me the contents of the trans_unit table, I get the correct German entry for Delete: Löschen (directly from the DB without translation). But the Generator module also has a Delete action which it tries to translate: L?schen. I am able to correct the __(Delete) function to utf8_encode(__ (Delete)) - but that's just stupid, and in Generators I can't do it anyway. I checked every documentation or bug request on that topic that I could find, so you are indead my last chance! Thank you for any help!!! Eddie --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups symfony users group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: about session handling
Can i use some thing like $_SESSION['name']=asim; in symfony That's pretty much exactly what this explains: http://www.symfony-project.org/book/1_2/06-Inside-the-Controller-Layer#chapter_06_sub_session_management --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups symfony users group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: modelo n:m embed forms
look this link ... http://www.blogs.uni-osnabrueck.de/rotapken/2009/03/13/symfony-merge-embedded-form/ On Aug 14, 6:42 am, juaninf juan...@gmail.com wrote: gestor: id: { type: INTEGER, primaryKey: true, required: true, autoIncrement: true } nombre: { type: VARCHAR, size: '45' } dni: { type: VARCHAR, size: '45' } pedido: id: { type: INTEGER, primaryKey: true, required: true, autoIncrement: true } hola: { type: VARCHAR, size: '45' } gestor_registra_gasto: gestor_id: { type: INTEGER, primaryKey: true, required: true, foreignTable: gestor, foreignReference: id, onDelete: cascade, onUpdate: cascade } pedido_id: { type: INTEGER, primaryKey: true, required: true, foreignTable: pedido, foreignReference: id, onDelete: cascade, onUpdate: cascade } concepto: { type: VARCHAR, size: '45', required: true } importe: { type: VARCHAR, size: '45', required: true } Good I am this model gestor: id: { type: INTEGER, primaryKey: true, required: true, autoIncrement: true } nombre: { type: VARCHAR, size: '45' } dni: { type: VARCHAR, size: '45' } pedido: id: { type: INTEGER, primaryKey: true, required: true, autoIncrement: true } hola: { type: VARCHAR, size: '45' } gestor_registra_gasto: gestor_id: { type: INTEGER, primaryKey: true, required: true, foreignTable: gestor, foreignReference: id, onDelete: cascade, onUpdate: cascade } pedido_id: { type: INTEGER, primaryKey: true, required: true, foreignTable: pedido, foreignReference: id, onDelete: cascade, onUpdate: cascade } concepto: { type: VARCHAR, size: '45', required: true } importe: { type: VARCHAR, size: '45', required: true } I created 3 modules Gestor -- gestor Gasto ---gestor_registra_gasto Pedido ---pedido I want make is that in the gasto form, I can embebed the two forms (Gestor and Pedido), but only the id's(this is easy i guess...read plus please),but so to select a id, for example de Gestor i see the other Gestor fields, but whitout edit this fields, only to see, and when i to select pedido this same form help me please --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups symfony users group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---