This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » General discussion » How to validate data for a restful service ?
How to validate data for a restful service ? [message #101838] Wed, 30 June 2010 12:17 Go to next message
nicolasv  is currently offline nicolasv
Messages: 7
Registered: April 2010
Junior Member
Hi,

I'm developing a restful web service with symfony, and I'd like to know if I'm following the right way for the data validation :

Can I create a form with validators but with no widgets , and check the validity of the parameters of a Post request by using the isValid() method.

Is it meaningful ? because It's odd to have a form and never render it.

Thanks in advance


http://twitter.com/n_vogel
Re: How to validate data for a restful service ? [message #102006 is a reply to message #101838 ] Mon, 05 July 2010 12:22 Go to previous messageGo to next message
nicolasv  is currently offline nicolasv
Messages: 7
Registered: April 2010
Junior Member
Anyone ?


http://twitter.com/n_vogel
Re: How to validate data for a restful service ? [message #103234 is a reply to message #102006 ] Thu, 29 July 2010 11:18 Go to previous messageGo to next message
Okin  is currently offline Okin
Messages: 4
Registered: July 2010
Junior Member
I have the same issue, does anybody knows how to do it ?

Thanks
Re: How to validate data for a restful service ? [message #103275 is a reply to message #101838 ] Fri, 30 July 2010 10:20 Go to previous messageGo to next message
nicolasv  is currently offline nicolasv
Messages: 7
Registered: April 2010
Junior Member
I think this a more common question : how to validate data with symfony ?

I think there's three ways :

* the symfony way, but how to do that ?
* use an other framework or library like Zend Validate ( http://framework.zend.com/manual/en/zend.validate.introducti on.html)
* coding yourself a method "validate" in the model class

All I want to know is can we do that with symfony, if not the choice is obvious


http://twitter.com/n_vogel
Re: How to validate data for a restful service ? [message #103284 is a reply to message #103275 ] Fri, 30 July 2010 11:39 Go to previous messageGo to next message
xplo  is currently offline xplo
Messages: 428
Registered: September 2008
Faithful Member
you can create a validator object without a form and just clean/validate with you validator object if you dont need/want the form.
Re: How to validate data for a restful service ? [message #103287 is a reply to message #101838 ] Fri, 30 July 2010 12:30 Go to previous messageGo to next message
Okin  is currently offline Okin
Messages: 4
Registered: July 2010
Junior Member
OK but is it a good practice to do so ?

symfony is supposed to be easily used for RESTful projects, there must be a clean way to validate params, even if they are not coming from a form ^^
Re: How to validate data for a restful service ? [message #103299 is a reply to message #103287 ] Fri, 30 July 2010 14:14 Go to previous messageGo to next message
xplo  is currently offline xplo
Messages: 428
Registered: September 2008
Faithful Member
i would believe it is good practice since it s reusable/light/fast but i never did RESTful projects so i have to step out ~
Re: How to validate data for a restful service ? [message #103310 is a reply to message #101838 ] Fri, 30 July 2010 15:29 Go to previous messageGo to next message
Okin  is currently offline Okin
Messages: 4
Registered: July 2010
Junior Member
OK, what I really wanted to know was if it was a good practice from symfony's point of view.
So according to your description that's ok Very Happy

Thanks Smile
Re: How to validate data for a restful service ? [message #103376 is a reply to message #103284 ] Sun, 01 August 2010 19:06 Go to previous message
nicolasv  is currently offline nicolasv
Messages: 7
Registered: April 2010
Junior Member
xplo wrote on Fri, 30 July 2010 11:39

you can create a validator object without a form and just clean/validate with you validator object if you dont need/want the form.



Seems good to me,


$validator = new sfValidatorString();

try {
  $validator->doClean($valueToValidate);
} catch (Exception $e) {
  //not valid
}

//valid





What do you think ?

An other question, the validation rules , where do we put them in the model or in the controller ?

For me it makes more sense to put them in the model.


[Updated on: Mon, 02 August 2010 11:02]


http://twitter.com/n_vogel
Previous Topic:filter for front_dev
Next Topic:phpBB Connector ?
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software