Re: [symfony-users] access object from validator

2010-04-07 Thread Mihai Rusoaie
Hello Cristophe!

Thanks for the hint, it was very useful! I managed to pass some of the
object's variables from the Form Class to the Validator Class through its
constructor. It works just fine:

// in the form class
$this-mergePostValidator(
new
ClientStatusValidatorSchema($this-getObject()-getUserId(),
$this-getObject()-getAvailability(),
$this-getObject()-countBdnClientContacts())
);

// in the validator class
class ClientStatusValidatorSchema extends sfValidatorSchema {

public function __construct($_current_user, $_availability,
$_contact_persons)
{
 $this-current_user = $_current_user;
 $this-contact_persons = $_contact_persons;
 $this-availability = $_availability;
}

private $current_user;
private $availability;
private $contact_persons;

protected function doClean($values) {

$errorSchema = new sfValidatorErrorSchema($this);

if(($this-current_user !=
sfContext::getInstance()-getUser()-getGuardUser()-getId())
($this-current_user != 0))
$errorSchema-addError(new sfValidatorError($this, 'This is not
your client!'), 'user_id');
//...



Regards,

Mihai Rusoaie
+40 72 RUSOAIE
www.rusoaie.com


On Tue, Apr 6, 2010 at 1:11 PM, NOOVEO - Christophe Brun
c.b...@nooveo.frwrote:

 Hi. I'm #far# from mastering Symfony but here are my two cents. I would say
 that validators are not intented to know anything else than the bunch of
 values to clean and validate, hence I don't see any way for them to know the
 form's object. But the form has access to all the values you need : tainted
 values, cleaned values, his object. Hence, I suppose that you should process
 your comparisons somewhere in the form's method, maybe doBind() or
 doUpdateObject().


 -Message d'origine-
 De : symfony-users@googlegroups.com [mailto:symfony-us...@googlegroups.com]
 De la part de Mihai Rusoaie
 Envoyé : jeudi 1 avril 2010 10:44
 À : symfony users
 Objet : [symfony-users] access object from validator

 Hello, all!

 Is there any way to access my object (the one before the form post) from a
 sfValidatorSchema ?

 When I had my validator inside the Form.class.php file, I could access the
 object with $this-getObject(), but from the sfValidatorSchema class I
 cannot access it like this.

 I need to compare the submitted values from a form with the previous
 values. Is there any other way to do this than to access the original object
 from the validator?

 Thank you!

 --
 If you want to report a vulnerability issue on symfony, please send it to
 security at symfony-project.com

 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.comsymfony-users%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/symfony-users?hl=en

 To unsubscribe, reply using remove me as the subject.


 --
 If you want to report a vulnerability issue on symfony, please send it to
 security at symfony-project.com

 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.comsymfony-users%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/symfony-users?hl=en


-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

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


RE: [symfony-users] access object from validator

2010-04-06 Thread NOOVEO - Christophe Brun
Hi. I'm #far# from mastering Symfony but here are my two cents. I would say 
that validators are not intented to know anything else than the bunch of values 
to clean and validate, hence I don't see any way for them to know the form's 
object. But the form has access to all the values you need : tainted values, 
cleaned values, his object. Hence, I suppose that you should process your 
comparisons somewhere in the form's method, maybe doBind() or doUpdateObject(). 


-Message d'origine-
De : symfony-users@googlegroups.com [mailto:symfony-us...@googlegroups.com] De 
la part de Mihai Rusoaie
Envoyé : jeudi 1 avril 2010 10:44
À : symfony users
Objet : [symfony-users] access object from validator

Hello, all!

Is there any way to access my object (the one before the form post) from a 
sfValidatorSchema ?

When I had my validator inside the Form.class.php file, I could access the 
object with $this-getObject(), but from the sfValidatorSchema class I cannot 
access it like this.

I need to compare the submitted values from a form with the previous values. Is 
there any other way to do this than to access the original object from the 
validator?

Thank you!

--
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

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

To unsubscribe, reply using remove me as the subject.


-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

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] access object from validator

2010-04-01 Thread Mihai Rusoaie
Hello, all!

Is there any way to access my object (the one before the form post)
from a sfValidatorSchema ?

When I had my validator inside the Form.class.php file, I could access
the object with $this-getObject(), but from the sfValidatorSchema
class I cannot access it like this.

I need to compare the submitted values from a form with the previous
values. Is there any other way to do this than to access the original
object from the validator?

Thank you!

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

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

To unsubscribe, reply using remove me as the subject.