<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Amphee Web Tech Pvt. Ltd. &#187; symfony plugins</title>
	<atom:link href="http://blog.amphee.com/index.php/tag/symfony-plugins/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.amphee.com</link>
	<description></description>
	<lastBuildDate>Wed, 04 May 2011 05:34:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		
	
	<!-- google ad injected by adsense-optimizer http://www.adsenseoptimizer.de -->
	<div  style="padding:3px; display: block; margin-left: auto; margin-right: auto; text-align: center;"><!-- Ad number: 1 --><script type="text/javascript"><!--
    	 
    	google_ad_client = "pub-0687753067406098"; google_alternate_color = "FFFFFF";
		google_ad_width = 468; google_ad_height = 60;
		google_ad_format = "468x60_as"; google_ad_type = "text_image";
		google_ad_channel =""; google_color_border = "A6C9E2";
		google_color_link = "FF3019"; google_color_bg = "FFFFFF";
		google_color_text = "000000"; google_color_url = "7EB544";
		google_ui_features = "rc:0"; //--></script>
		<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div>	<item>
		<title>Symfony Tutorials: Using sfValidatorCallback</title>
		<link>http://blog.amphee.com/index.php/2010/10/26/symfony-tutorials-using-sfvalidatorcallback/</link>
		<comments>http://blog.amphee.com/index.php/2010/10/26/symfony-tutorials-using-sfvalidatorcallback/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 10:52:56 +0000</pubDate>
		<dc:creator>kiran vadariya</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[sfValidatorCallback]]></category>
		<category><![CDATA[symfony plugins]]></category>
		<category><![CDATA[symfony tutorials]]></category>

		<guid isPermaLink="false">http://blog.amphee.com/?p=286</guid>
		<description><![CDATA[Many times when you&#8217;re validating forms in symfony you need to do more than what the standard validators allow, and since you&#8217;re lazy you don&#8217;t feel like creating your own custom validator. sfValidatorCallback to the rescue!
sfValidatorCallback allows you to define your own validation function to be used for a given form field. It also allows [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Many times when you&#8217;re validating forms in symfony you need to do more than what the standard validators allow, and since you&#8217;re lazy you don&#8217;t feel like creating your own custom validator. sfValidatorCallback to the rescue!</p>
<p>sfValidatorCallback allows you to define your own validation function to be used for a given form field. It also allows you to scrub the data in any way you see fit. We&#8217;ll look at both uses.<br />
A Psudo-example</p>
<p>Since you can use the callback validator for literally anything you want, here&#8217;s a simple example of how to use a function in your model to validate a field on the form for that model object</p>
<p>In MyObjectForm.class.php:</p>
<p><strong>1.public function configure() {<br />
2. &#8230;<br />
3. $this-&gt;widgetSchema['some_text_field'] =<br />
4. new sfWidgetFormTextArea(array(&#8216;required&#8217;=&gt;false));<br />
5.<br />
6. $this-&gt;validatorSchema['some_text_field'] = new sfValidatorCallback(<br />
7. array(&#8216;callback&#8217;=&gt;<br />
8. array($this-&gt;getObject(), &#8217;someTextFieldValidatorHook&#8217;)<br />
9. )<br />
10. );<br />
11. &#8230;<br />
12. }</strong></p>
<p>Here we see that we&#8217;re setting the validator for some_text_field to our call back. The first parameter to the callback takes our options. For these we need to pass a callback, which takes the same parameters as PHP&#8217;s call_user_func. Since we want to call a method in our base model object, we&#8217;ll use an array as the first parameter to pass our object and the method we want to call. $this-&gt;getObject(); returns the model object of the form, and someTextFieldValidatorHook is what we want to call.</p>
<p>So, in MyObject.php, in your model folder:<br />
<strong><br />
1. public function someTextFieldValidatorhook($validator, $value) {<br />
2.<br />
3. //test $value, set $pass if its ok<br />
4.<br />
5. if($pass) {<br />
6. return $value;<br />
7. }<br />
8.<br />
9. else {<br />
10.<br />
11. $message = &#8220;I can write whatever I want here based on the results &#8220;.<br />
12. &#8220;of my test. The point is that this field didn&#8217;t validate though&#8221;;<br />
13.<br />
14. throw new sfValidatorError($validator, $message);<br />
15.<br />
16. }<br />
17.<br />
18. }<br />
</strong><br />
We can see here that the magic is throwing the exception when your test fails. The exception bubbles up and is caught by the form stuff on a higher level to render the error message to the user as you would expect.</p>
<p>Now, there are are a few things to keep in mind:</p>
<p>* sfValidatorError can take a message code and error messages as its second and third parameters. However, most of the time you use the call back, you&#8217;ll want to generate the error message internally, since its dependant on the test you just wrote. Still, remember that you can respond with canned error messages if you want.<br />
* Your data hasn&#8217;t been saved yet, so you really have no notion of what the other fields are unless you grab the request object and look at them.<br />
* You can make your validation method static if you want, but sometimes its helpful to have the old values of your current object, or you may have expanded your model object to do things beyond the standard get/set stuff.</p>
<p><strong>Is This Cool?</strong></p>
<p>Some may argue that this kind of validation doesn&#8217;t belong in your model object, and a separate validator object should be created. I can see that point, and I think I mostly agree with it, but there are exceptions to every rule. Sometimes this simple approach is the correct one, and it can streamline your development.</p>
<p>Still, you should keep in mind that your validation function is going to throw a validator exception, so indicate that you&#8217;ll need to catch it in your documentation if the test fails, or name the method something to show that it should only be used as a hook to the validator, as I&#8217;ve done with someTextFieldValidatorHook.<br />
Scrubbing</p>
<p>One last benefit of the validator is that it gives you a good way to scrub your data before you save it. Since your callback function (someTextFieldValidatorHook in our case) takes the value in to verify it and returns it at the end if the test passed, you can technically change it to whatever you want. Some possible ideas are:</p>
<p>1. Removing HTML<br />
2. Converting text links to actual links (bad example as you should probably do this on output)<br />
3. Formatting Phone Numbers<br />
4. Etc, etc</p>
<p><strong>That&#8217;s It</strong></p>
<p>Hope you found this useful. Feel free to share how you&#8217;ve used the callback validator in your applications.</p>
<p>You can find the original post here : <a href="http://www.pbtg.com/blogs/jim/tag/symfony" target="_blank">http://www.pbtg.com/blogs/jim/tag/symfony</a></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://blog.amphee.com/index.php/2010/10/26/symfony-tutorials-using-sfvalidatorcallback/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interesting symfony plugins: sfSyncContentPlugin</title>
		<link>http://blog.amphee.com/index.php/2010/06/21/interesting-symfony-plugins-sfsynccontentplugin/</link>
		<comments>http://blog.amphee.com/index.php/2010/06/21/interesting-symfony-plugins-sfsynccontentplugin/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 06:07:07 +0000</pubDate>
		<dc:creator>kiran vadariya</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[symfony development]]></category>
		<category><![CDATA[symfony plugins]]></category>

		<guid isPermaLink="false">http://blog.amphee.com/?p=163</guid>
		<description><![CDATA[With the amount of plugins published in the symfony site, many great plugins get lost in the maze. With this series of posts, we would like to bring some attention to plugins we use every day or that we think are essential for any symfony developer.
sfSyncContentPlugin
Deploying symfony applications is always a key part of developing [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>With the amount of plugins published in the symfony site, many great plugins get lost in the maze. With this series of posts, we would like to bring some attention to plugins we use every day or that we think are essential for any symfony developer.</p>
<h2>sfSyncContentPlugin</h2>
<p>Deploying symfony applications is always a key part of developing and maintaining websites that run on symfony. It is always a recommended practice to do development on a local environment or dedicated development server. It is also recommended to have a QA/staging server that is as close as possible to your production server. Using this well proven method you can spot problems and bugs before everybody else sees or experiences them, you know, those bugs that “only” happen in production, don’t tell me that it never happened to you, I won’t believe you.</p>
<p>Anyway, making changes in a live site is not only not recommended, it should never be done!</p>
<p>When developing and testing symfony applications, a lot of times you need to have a copy of the live data. Or you may have a staging server where you make changes before pushing them to a live site in a production server. symfony already provides a way to deploy code changes to a remote server, but what about uploaded and data files? And database content?</p>
<p>Since we discovered and started using it, we can’t live without the<a href="http://www.symfony-project.org/plugins/sfSyncContentPlugin">sfSyncContentPlugin plugin</a> by Tom Boutell and Alex Gilbert, also developers of<a href="http://www.apostrophenow.com/">Apostrophe CMS</a>. This plugin helps with all the tasks and needs described above. Using it is quite simple. All you need to do is define your servers in config/properties.ini like this:</p>
<pre>[qa]
  host=qa.example.com
  port=22
  user=user
  dir=/var/www/mysite

[prod]
  host=www.example.com
  port=22
  user=user
  dir=/var/www/mysite

[staging]
  host=staging.example.com
  port=22
  user=user
  dir=/var/www/mysite</pre>
<p>Make sure to use SSH keys to authenticate to your remote servers, so you don’t get asked again and again for passwords. Then just run the following symfony tasks:</p>
<pre>
<pre># Migrate files and DB from development to qa
./symfony project:sync-content frontend dev to qa@qa

# Migrate files and DB to production (always make a backup of production before doing this!)
./symfony project:sync-content frontend dev to prod@prod

# Migrate files and DB from QA into development
./symfony project:sync-content frontend dev from prod@prod</pre>
</pre>
<p>Files and DB content are copied accordingly, almost magically. It saves so much time, but please make sure you understand and check the order that you apply in the symfony task. With the power this plugin provides, is very easy, by mistake, to overwrite production data, so again, always make a backup!</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://blog.amphee.com/index.php/2010/06/21/interesting-symfony-plugins-sfsynccontentplugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

