<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Where Should Data Be Validated In Objects?</title>
	<atom:link href="http://blog.alexmace.co.uk/2009/08/16/dealing-with-problems-in-user-provided-data/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.alexmace.co.uk/2009/08/16/dealing-with-problems-in-user-provided-data/</link>
	<description>Life &#38; Web Development</description>
	<lastBuildDate>Thu, 27 May 2010 22:21:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: David Goodwin</title>
		<link>http://blog.alexmace.co.uk/2009/08/16/dealing-with-problems-in-user-provided-data/comment-page-1/#comment-6324</link>
		<dc:creator>David Goodwin</dc:creator>
		<pubDate>Wed, 21 Oct 2009 06:37:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.alexmace.co.uk/?p=315#comment-6324</guid>
		<description>Hi!

I disagree; I think objects should validate data. My favourite ORM, Propel, does an excellent job of this... 

Namely, you can define validation rules on a per field basis (e.g. minlength, maxlength, regexp matches etc) and then you can optionally call $user-&gt;validate() before $user-&gt;save(). 

If you don&#039;t call $user-&gt;validate() then your data will probably get saved (assuming there are no database constraints on fields which will result in a db exception being raised

When calling validate(), you can optionally ask it to validate only certain fields - allowing you to partially populate an object (e.g. on a multi-page form). 

Finally, when validation fails, it doesn&#039;t return an exception - validate() returns true/false; if it returns false, it&#039;s up to you (the programmer) to call getValidationFailures() which returns a list of objects you can iterate over - each has teh field name and the validation failure message you specified in the schema.xml file.

Anyway, I like it - I&#039;ve not yet looked at Doctrine in any depth, but don&#039;t think it offers the same functionality (but I may be wrong).

David</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>I disagree; I think objects should validate data. My favourite ORM, Propel, does an excellent job of this&#8230; </p>
<p>Namely, you can define validation rules on a per field basis (e.g. minlength, maxlength, regexp matches etc) and then you can optionally call $user-&gt;validate() before $user-&gt;save(). </p>
<p>If you don&#8217;t call $user-&gt;validate() then your data will probably get saved (assuming there are no database constraints on fields which will result in a db exception being raised</p>
<p>When calling validate(), you can optionally ask it to validate only certain fields &#8211; allowing you to partially populate an object (e.g. on a multi-page form). </p>
<p>Finally, when validation fails, it doesn&#8217;t return an exception &#8211; validate() returns true/false; if it returns false, it&#8217;s up to you (the programmer) to call getValidationFailures() which returns a list of objects you can iterate over &#8211; each has teh field name and the validation failure message you specified in the schema.xml file.</p>
<p>Anyway, I like it &#8211; I&#8217;ve not yet looked at Doctrine in any depth, but don&#8217;t think it offers the same functionality (but I may be wrong).</p>
<p>David</p>
]]></content:encoded>
	</item>
</channel>
</rss>
