<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>jonocode - a developer&#039;s blog</title>
	<atom:link href="http://jonocode.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonocode.wordpress.com</link>
	<description>PHP, MySQL, CSS, javascript, HTML, symfony, jQuery, the list goes on...</description>
	<lastBuildDate>Sun, 29 Nov 2009 21:56:44 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='jonocode.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/f6ef3ed3dae116b2a859bcd8a79be58f?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>jonocode - a developer&#039;s blog</title>
		<link>http://jonocode.wordpress.com</link>
	</image>
			<item>
		<title>Symfony prints your titles twice</title>
		<link>http://jonocode.wordpress.com/2009/11/29/symfony-prints-your-titles-twice/</link>
		<comments>http://jonocode.wordpress.com/2009/11/29/symfony-prints-your-titles-twice/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 21:56:44 +0000</pubDate>
		<dc:creator>jjmontgo</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[Symfony 1.0]]></category>

		<guid isPermaLink="false">http://jonocode.wordpress.com/?p=129</guid>
		<description><![CDATA[I recently received a request from an SEO / online marketing company to remove the extra title from one of our sites.  Symfony was displaying the title information for every page twice; once in the title tag, and again in as a meta tag with name=&#8221;title&#8221;.
Google was not displaying the title they had given [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=129&subd=jonocode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I recently received a request from an SEO / online marketing company to remove the extra title from one of our sites.  Symfony was displaying the title information for every page twice; once in the title tag, and again in as a meta tag with name=&#8221;title&#8221;.</p>
<p>Google was not displaying the title they had given the index page, and there was a concern that Google considered the title duplication to be spam.</p>
<p>Both the title tag and the meta tags are generated from the helper functions include_title and include_metas, respectively.  I could find no easy, configuration-based way to tell include_metas to not include the title meta, so I decided replace the helper with the following:</p>
<pre class="brush: plain;">
&lt;?php

foreach ( sfContext::getInstance()-&gt;getResponse()-&gt;getMetas() as $name =&gt; $content ):
  if ( $name != 'title' ):
    echo tag('meta', array('name' =&gt; $name, 'content' =&gt; $content)).&quot;\n&quot;;
  endif;
endforeach;

?&gt;
</pre>
<p>About a month later there is no change in how Google displays the site&#8217;s index page.  Perhaps it will take longer to find out if this will change it.  Or if it won&#8217;t change anything.</p>
<p>Have you had any trouble with Google not displaying your page titles in their results?  Do you know if displaying the same title twice, both in the title tag and in the meta title tag, is affecting things?</p>
<p>Please do comment.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jonocode.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jonocode.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jonocode.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jonocode.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jonocode.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jonocode.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jonocode.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jonocode.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jonocode.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jonocode.wordpress.com/129/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=129&subd=jonocode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jonocode.wordpress.com/2009/11/29/symfony-prints-your-titles-twice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d13feaa45035e90bbbf6754ea3de3eb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">developerstravels</media:title>
		</media:content>
	</item>
		<item>
		<title>Giving your symfony apps better urls</title>
		<link>http://jonocode.wordpress.com/2009/09/30/giving-your-symfony-apps-better-urls/</link>
		<comments>http://jonocode.wordpress.com/2009/09/30/giving-your-symfony-apps-better-urls/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 22:34:14 +0000</pubDate>
		<dc:creator>jjmontgo</dc:creator>
				<category><![CDATA[Setup]]></category>
		<category><![CDATA[Symfony 1.0]]></category>
		<category><![CDATA[Symfony 1.2]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://jonocode.wordpress.com/?p=127</guid>
		<description><![CDATA[I love pretty URLs.  I don&#8217;t like file name extensions unless they end with .html.
All versions of symfony save me from address bar ugliness, but only for the first application I create.  Everything else is ass.php/backwards.
I&#8217;m going to give you two ways of beautifying your second, third, and forth applications so you can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=127&subd=jonocode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I love pretty URLs.  I don&#8217;t like file name extensions unless they end with .html.</p>
<p>All versions of symfony save me from address bar ugliness, but only for the first application I create.  Everything else is ass.php/backwards.</p>
<p>I&#8217;m going to give you two ways of beautifying your second, third, and forth applications so you can http://www.get.your/application/looking/sexy.  Both methods involve creating a subdirectory.</p>
<p><strong>Put it all in a subdirectory, and symlink your way out</strong></p>
<p>So if you have an app named &#8220;admin,&#8221; you can do the following:</p>
<ol>
<li>Create a directory in your web folder called admin</li>
<li>Copy your admin.php and admin_dev.php into this folder</li>
<li>Copy the .htaccess file into this folder</li>
<li>Rename admin.php to index.php</li>
<li>Edit the file now named index.php, and change the require_once statement at the top so it&#8217;s an extra directory back</li>
<li>Symbolically link the js, css, images, and uploads directories from within the admin directory to the directory above; so from your app directory: <code>ln -s ../js</code></li>
</ol>
<p>This is what I usually do in a Linux environment.  However, I&#8217;m developing on a Windows box, and symbolic links don&#8217;t translate easily between Windows and Linux.  So here&#8217;s the second option, without using symbolic links:</p>
<p><strong>Put just the .htaccess in a subdirectory</strong></p>
<ol>
<li>As before, create a subdirectory in your web folder for the admin.</li>
<li>Copy the .htaccess file in, and at the very bottom of the file, change index.php to ../admin.php.  It should read <code>RewriteRule ^(.*)$ ../admin.php [QSA,L]</code></li>
<li>Edit your routing.yml file for the admin app, and append /admin/ to all of your routes.</li>
</ol>
<p>That should about cover it.  Also remember to set no_script_name to on in each of your applications.</p>
<p>Enjoy.</p>
<p>Alternative methods?  Please leave comments.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jonocode.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jonocode.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jonocode.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jonocode.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jonocode.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jonocode.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jonocode.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jonocode.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jonocode.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jonocode.wordpress.com/127/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=127&subd=jonocode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jonocode.wordpress.com/2009/09/30/giving-your-symfony-apps-better-urls/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d13feaa45035e90bbbf6754ea3de3eb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">developerstravels</media:title>
		</media:content>
	</item>
		<item>
		<title>Disabling the submit button with jQuery to prevent extra submissions</title>
		<link>http://jonocode.wordpress.com/2009/09/29/disabling-the-submit-button-with-jquery-to-prevent-extra-submissions/</link>
		<comments>http://jonocode.wordpress.com/2009/09/29/disabling-the-submit-button-with-jquery-to-prevent-extra-submissions/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 00:33:25 +0000</pubDate>
		<dc:creator>jjmontgo</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[forms]]></category>

		<guid isPermaLink="false">http://jonocode.wordpress.com/?p=125</guid>
		<description><![CDATA[It happens.
Not often, but once in a while a user submits the same thing.  Twice, maybe three times, and each just a second or two apart.
It&#8217;s easy to understand why.  They click the submit button and then &#8230; nothing happens.  If it doesn&#8217;t work right away, we assume it&#8217;s not working.  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=125&subd=jonocode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>It happens.</p>
<p>Not often, but once in a while a user submits the same thing.  Twice, maybe three times, and each just a second or two apart.</p>
<p>It&#8217;s easy to understand why.  They click the submit button and then &#8230; nothing happens.  If it doesn&#8217;t work right away, we assume it&#8217;s not working.  The solution?  Hit the button again!  Hit it five times until finally, it seems to work.</p>
<p>There are two things you need to do to stop this from happening.</p>
<ol>
<li>Assure the user they successfully clicked the button, and they only have to wait a moment for the form to be processed.</li>
<li>Stop the user from hitting the button again.</li>
</ol>
<p>I&#8217;m a jQuery newbie, but it wasn&#8217;t long before I was in love with this javascript library.  Here is my solution:</p>
<ol>
<li><a href="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js">Download the jQuery library</a> if you haven&#8217;t already, and drop it in your js directory if you&#8217;re using Symfony.</li>
<li>Reference the jquery library in your template, like so:
<pre class="brush: php;">
&lt;?php use_javascript('jquery') ?&gt;
</pre>
</li>
<li>And finally, here&#8217;s the source code:</li>
</ol>
<pre class="brush: plain;">
&lt;script type=&quot;text/javascript&quot;&gt;
  $(document).ready(function(){
    $(&quot;input[type='submit']&quot;).attr(&quot;disabled&quot;, false);

    $(&quot;form&quot;).submit(function(){
      $(&quot;input[type='submit']&quot;).attr(&quot;disabled&quot;, true).val(&quot;Please wait...&quot;);
      return false;
    })
  })
&lt;/script&gt;
</pre>
<p>I love the simplicity.  </p>
<p>Once the document is ready, make sure every submit button on the page is enabled.  In Firefox 3.5, if I click the back button to go back to the form after submitting, the submit button stays disabled.  I&#8217;m not sure why; the value attribute is correct, but it stays disabled, even if you refresh.</p>
<p>In the next few statements, I add an onsubmit event to the form.  If you have javascript validation on your form, you&#8217;ll have to execute your validation from within this function.  </p>
<p>The function finds all submit buttons within the form, disables them, and changes their value to &#8220;Please wait&#8230;&#8221;.  All of this is done dynamically, without altering the form directly in my html.  Love it.</p>
<p>Does anyone have any server-side solutions to this problem?  If you do I&#8217;d love to hear about them.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jonocode.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jonocode.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jonocode.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jonocode.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jonocode.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jonocode.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jonocode.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jonocode.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jonocode.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jonocode.wordpress.com/125/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=125&subd=jonocode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jonocode.wordpress.com/2009/09/29/disabling-the-submit-button-with-jquery-to-prevent-extra-submissions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d13feaa45035e90bbbf6754ea3de3eb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">developerstravels</media:title>
		</media:content>
	</item>
		<item>
		<title>Country codes in YAML format</title>
		<link>http://jonocode.wordpress.com/2009/09/20/country-codes-in-yaml-format/</link>
		<comments>http://jonocode.wordpress.com/2009/09/20/country-codes-in-yaml-format/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 19:00:05 +0000</pubDate>
		<dc:creator>jjmontgo</dc:creator>
				<category><![CDATA[Symfony 1.2]]></category>
		<category><![CDATA[YAML]]></category>
		<category><![CDATA[country codes]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://jonocode.wordpress.com/?p=121</guid>
		<description><![CDATA[Here are all the country codes in YAML format for your downloading pleasure!  You may place them in your app.yml (for symfony users) and call the list with sfConfig::get(&#8216;app_countries&#8217;).

all:
  .lists:
    countries:
      CA:	Canada
      US:	United States of America
     [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=121&subd=jonocode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Here are all the country codes in YAML format for your downloading pleasure!  You may place them in your app.yml (for symfony users) and call the list with sfConfig::get(&#8216;app_countries&#8217;).</p>
<pre>
all:
  .lists:
    countries:
      CA:	Canada
      US:	United States of America
      AD: Andorra
      AE:	United Arab Emirates
      AF:	Afghanistan
      AG:	Antigua &amp; Barbuda
      AI:	Anguilla
      AL:	Albania
      AM:	Armenia
      AN:	Netherlands Antilles
      AO:	Angola
      AQ:	Antarctica
      AR:	Argentina
      AS:	American Samoa
      AT:	Austria
      AU:	Australia
      AW:	Aruba
      AZ:	Azerbaijan
      BA:	Bosnia and Herzegovina
      BB:	Barbados
      BD:	Bangladesh
      BE:	Belgium
      BF:	Burkina Faso
      BG:	Bulgaria
      BH:	Bahrain
      BI:	Burundi
      BJ:	Benin
      BM:	Bermuda
      BN:	Brunei Darussalam
      BO:	Bolivia
      BR:	Brazil
      BS:	Bahama
      BT:	Bhutan
      BU:	Burma (no longer exists)
      BV:	Bouvet Island
      BW:	Botswana
      BY:	Belarus
      BZ:	Belize
      CC:	Cocos (Keeling) Islands
      CF:	Central African Republic
      CG:	Congo
      CH:	Switzerland
      CI:	Côte D'ivoire (Ivory Coast)
      CK:	Cook Iislands
      CL:	Chile
      CM:	Cameroon
      CN:	China
      CO:	Colombia
      CR:	Costa Rica
      CS:	Czechoslovakia (no longer exists)
      CU:	Cuba
      CV:	Cape Verde
      CX:	Christmas Island
      CY:	Cyprus
      CZ:	Czech Republic
      DD:	German Democratic Republic (no longer exists)
      DE:	Germany
      DJ:	Djibouti
      DK:	Denmark
      DM:	Dominica
      DO:	Dominican Republic
      DZ:	Algeria
      EC:	Ecuador
      EE:	Estonia
      EG:	Egypt
      EH:	Western Sahara
      ER:	Eritrea
      ES:	Spain
      ET:	Ethiopia
      FI:	Finland
      FJ:	Fiji
      FK:	Falkland Islands (Malvinas)
      FM:	Micronesia
      FO:	Faroe Islands
      FR:	France
      FX:	France, Metropolitan
      GA:	Gabon
      GB:	United Kingdom (Great Britain)
      GD:	Grenada
      GE:	Georgia
      GF:	French Guiana
      GH:	Ghana
      GI:	Gibraltar
      GL:	Greenland
      GM:	Gambia
      GN:	Guinea
      GP:	Guadeloupe
      GQ:	Equatorial Guinea
      GR:	Greece
      GS:	South Georgia and the South Sandwich Islands
      GT:	Guatemala
      GU:	Guam
      GW:	Guinea-Bissau
      GY:	Guyana
      HK:	Hong Kong
      HM:	Heard &amp; McDonald Islands
      HN:	Honduras
      HR:	Croatia
      HT:	Haiti
      HU:	Hungary
      ID:	Indonesia
      IE:	Ireland
      IL:	Israel
      IN:	India
      IO:	British Indian Ocean Territory
      IQ:	Iraq
      IR:	Islamic Republic of Iran
      IS:	Iceland
      IT:	Italy
      JM:	Jamaica
      JO:	Jordan
      JP:	Japan
      KE:	Kenya
      KG:	Kyrgyzstan
      KH:	Cambodia
      KI:	Kiribati
      KM:	Comoros
      KN:	St. Kitts and Nevis
      KP:	Korea, Democratic People's Republic of
      KR:	Korea, Republic of
      KW:	Kuwait
      KY:	Cayman Islands
      KZ:	Kazakhstan
      LA:	Lao People's Democratic Republic
      LB:	Lebanon
      LC:	Saint Lucia
      LI:	Liechtenstein
      LK:	Sri Lanka
      LR:	Liberia
      LS:	Lesotho
      LT:	Lithuania
      LU:	Luxembourg
      LV:	Latvia
      LY:	Libyan Arab Jamahiriya
      MA:	Morocco
      MC:	Monaco
      MD:	Moldova, Republic of
      MG:	Madagascar
      MH:	Marshall Islands
      ML:	Mali
      MN:	Mongolia
      MM:	Myanmar
      MO:	Macau
      MP:	Northern Mariana Islands
      MQ:	Martinique
      MR:	Mauritania
      MS:	Monserrat
      MT:	Malta
      MU:	Mauritius
      MV:	Maldives
      MW:	Malawi
      MX:	Mexico
      MY:	Malaysia
      MZ:	Mozambique
      NA:	Namibia
      NC:	New Caledonia
      NE:	Niger
      NF:	Norfolk Island
      NG:	Nigeria
      NI:	Nicaragua
      NL:	Netherlands
      "NO":	Norway
      NP:	Nepal
      NR:	Nauru
      NT:	Neutral Zone (no longer exists)
      NU:	Niue
      NZ:	New Zealand
      OM:	Oman
      PA:	Panama
      PE:	Peru
      PF:	French Polynesia
      PG:	Papua New Guinea
      PH:	Philippines
      PK:	Pakistan
      PL:	Poland
      PM:	St. Pierre &amp; Miquelon
      PN:	Pitcairn
      PR:	Puerto Rico
      PT:	Portugal
      PW:	Palau
      PY:	Paraguay
      QA:	Qatar
      RE:	Réunion
      RO:	Romania
      RU:	Russian Federation
      RW:	Rwanda
      SA:	Saudi Arabia
      SB:	Solomon Islands
      SC:	Seychelles
      SD:	Sudan
      SE:	Sweden
      SG:	Singapore
      SH:	St. Helena
      SI:	Slovenia
      SJ:	Svalbard &amp; Jan Mayen Islands
      SK:	Slovakia
      SL:	Sierra Leone
      SM:	San Marino
      SN:	Senegal
      SO:	Somalia
      SR:	Suriname
      ST:	Sao Tome &amp; Principe
      SU:	Union of Soviet Socialist Republics (no longer exists)
      SV:	El Salvador
      SY:	Syrian Arab Republic
      SZ:	Swaziland
      TC:	Turks &amp; Caicos Islands
      TD:	Chad
      TF:	French Southern Territories
      TG:	Togo
      TH:	Thailand
      TJ:	Tajikistan
      TK:	Tokelau
      TM:	Turkmenistan
      TN:	Tunisia
      TO:	Tonga
      TP:	East Timor
      TR:	Turkey
      TT:	Trinidad &amp; Tobago
      TV:	Tuvalu
      TW:	Taiwan, Province of China
      TZ:	Tanzania, United Republic of
      UA:	Ukraine
      UG:	Uganda
      UM:	United States Minor Outlying Islands
      UY:	Uruguay
      UZ:	Uzbekistan
      VA:	Vatican City State (Holy See)
      VC:	St. Vincent &amp; the Grenadines
      VE:	Venezuela
      VG:	British Virgin Islands
      VI:	United States Virgin Islands
      VN:	Viet Nam
      VU:	Vanuatu
      WF:	Wallis &amp; Futuna Islands
      WS:	Samoa
      YD:	Democratic Yemen (no longer exists)
      YE:	Yemen
      YT:	Mayotte
      YU:	Yugoslavia
      ZA:	South Africa
      ZM:	Zambia
      ZR:	Zaire
      ZW:	Zimbabwe
      ZZ:	Unknown or unspecified country
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jonocode.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jonocode.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jonocode.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jonocode.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jonocode.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jonocode.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jonocode.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jonocode.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jonocode.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jonocode.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=121&subd=jonocode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jonocode.wordpress.com/2009/09/20/country-codes-in-yaml-format/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d13feaa45035e90bbbf6754ea3de3eb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">developerstravels</media:title>
		</media:content>
	</item>
		<item>
		<title>Securing multi-user CRUD operations through the myUser class in Symfony</title>
		<link>http://jonocode.wordpress.com/2009/08/17/securing-multi-user-crud-operations-through-the-myuser-class-in-symfony/</link>
		<comments>http://jonocode.wordpress.com/2009/08/17/securing-multi-user-crud-operations-through-the-myuser-class-in-symfony/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 00:42:52 +0000</pubDate>
		<dc:creator>jjmontgo</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony 1.2]]></category>

		<guid isPermaLink="false">http://jonocode.wordpress.com/?p=118</guid>
		<description><![CDATA[Symfony has automated the process of creating a CRUD application, and even has built-in CSRF protection.
However, for a site with multiple users, the generated CRUD code just won&#8217;t do.
In my schema, each row of a model is owned by a user, according to their user_id.  In the dashboard application I am building, each user [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=118&subd=jonocode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Symfony has automated the process of creating a CRUD application, and even has built-in CSRF protection.</p>
<p>However, for a site with multiple users, the generated CRUD code just won&#8217;t do.</p>
<p>In my schema, each row of a model is owned by a user, according to their user_id.  In the dashboard application I am building, each user has a list of programs.</p>
<p>They can create, read, update and delete each program that they own.</p>
<p>But the generated actions would allow users access to other user&#8217;s programs, simply by changing the id in URLs such as <code>/program/edit/id/1</code>.</p>
<p>My solution?  Store the user_id of the currently logged in user in myUser.class.php.  Since the myUser class has ownership of the id of the currently logged in user, I thought it was appropriate to implement convenience getters and setters for the dashboard here.</p>
<p>So my list action would contain:</p>
<pre class="brush: php;">
$this-&gt;programs = $this-&gt;getUser()-&gt;getPrograms();
</pre>
<p>The <code>myUser::getPrograms()</code> method is implemented like so:</p>
<pre class="brush: php;">
public function getPrograms()
{
  return Doctrine::getTable('Program')-&gt;fetchByOwner($this-&gt;getId());
}

public function getProgram($pk)
{
  $program = Doctrine::getTable('Program')-&gt;find($pk);
  return $this-&gt;hasOwnershipOf($program) ? $program : false;
}

public function hasOwnershipOf($row)
{
  if ( isset($row['user_id']) )
  {
    if ( $row['user_id'] == $this-&gt;getId() )
    {
      return true;
    }
  }
  return false;
}
</pre>
<p>Adding the <code>myUser::fetchByOwner()</code> method leaves the model functionality open to being called from another administrative application other than the dashboard.  You could use a Doctrine magic method here, however I would prefer to return programs in alphabetical order (or perhaps allow for other options to be passed in using a Doctrine_Query as a second parameter).</p>
<p>For <code>myUser::getProgram($pk)</code>, I simply use the <code>::find()</code> magic method in doctrine to retrieve the object by primary key, as usual, and then return it only if it matches the user_id of the logged-in user.</p>
<p>Writing for multiple users is common place for web-based applications.  However, it&#8217;s something I don&#8217;t usually deal with at work where I write simple, single-user back ends for editing website content.</p>
<p>Is there a more elegant way of handling user ownership of database content?  Perhaps by writing a doctrine behavior?  How do you usually go about it?  </p>
<p>Please comment.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jonocode.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jonocode.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jonocode.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jonocode.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jonocode.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jonocode.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jonocode.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jonocode.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jonocode.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jonocode.wordpress.com/118/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=118&subd=jonocode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jonocode.wordpress.com/2009/08/17/securing-multi-user-crud-operations-through-the-myuser-class-in-symfony/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d13feaa45035e90bbbf6754ea3de3eb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">developerstravels</media:title>
		</media:content>
	</item>
		<item>
		<title>Create a dynamic CSS module in Symfony 1.2 fast</title>
		<link>http://jonocode.wordpress.com/2009/08/12/create-a-dynamic-css-module-in-symfony-1-2-fast/</link>
		<comments>http://jonocode.wordpress.com/2009/08/12/create-a-dynamic-css-module-in-symfony-1-2-fast/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 01:01:30 +0000</pubDate>
		<dc:creator>jjmontgo</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony 1.2]]></category>
		<category><![CDATA[dynamic css]]></category>

		<guid isPermaLink="false">http://jonocode.wordpress.com/?p=111</guid>
		<description><![CDATA[I&#8217;m sure there are a number of ways you can handle this.  There are also tons of modifications you can do to make it more useful, or better adapted to your particular needs.  This post will quickly illustrate one way to create a dynamic stylesheet in Symfony 1.2.
I just finished writing a module [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=111&subd=jonocode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;m sure there are a number of ways you can handle this.  There are also tons of modifications you can do to make it more useful, or better adapted to your particular needs.  This post will quickly illustrate one way to create a dynamic stylesheet in Symfony 1.2.</p>
<p>I just finished writing a module that allows my users to change their background color.  So I thought I&#8217;d share a similar way of doing this with an example.</p>
<p>Create a new doctrine model.  Since we&#8217;re keeping things simple, our style sheet will only have one editable element: the body tag&#8217;s background-image.</p>
<pre class="brush: css;">
DynamicCSS:
  columns:
    identifier: string(255)
    background_color: string(255)
</pre>
<p>Add a fixture and load it up:</p>
<p><em>/data/fixtures/fixtures.yml</em></p>
<pre class="brush: css;">
DynamicCSS:
  black:
    identifier: &quot;main&quot;
    background_color: &quot;#000000&quot;
</pre>
<pre class="brush: bash;">
$ symfony doctrine:build-all-reload
</pre>
<p>The identifier will be the stylesheet&#8217;s name.  You&#8217;ll see it in the route, which you&#8217;ll add now:</p>
<p><em>/apps/frontend/config/routing.yml</em></p>
<pre class="brush: css;">
dynamiccss:
  url: /dynamiccss/:identifier.css
  param: { module: dynamiccss, action: render }
</pre>
<p>Create a new module:</p>
<pre class="brush: bash;">
$ symfony init-module frontend dynamiccss
</pre>
<p>This module will be used to render a dynamic style sheet.  You&#8217;ll want to make sure it doesn&#8217;t render the layout, and that it returns a content type of &#8216;text/css&#8217;.  So edit the actions file and add a preExecute() method.  Of course, you&#8217;ll also need a method to fetch the style sheet and render it.</p>
<p><em>/apps/frontend/modules/dynamiccss/actions/actions.class.php</em></p>
<pre class="brush: php;">
...
  public function preExecute()
  {
    $this-&gt;setLayout(false);
    $this-&gt;getResponse()-&gt;setContentType('text/css');
  }

  public function executeRender()
  {
    $this-&gt;stylesheet = Doctrine::getTable('DynamicCSS')
      -&gt;getByIdentifier($request-&gt;getParameter('identifier'));
    $this-&gt;forward404Unless($this-&gt;stylesheet);
  }
...
</pre>
<p>Next we&#8217;ll add the template, which is at this point is very simplistic.  You&#8217;ll need to have that ::getByIdentifier() method implemented in the DynamicCSSTable class, as well.</p>
<p><em>/apps/frontend/modules/dynamiccss/templates/renderSuccess.php</em></p>
<pre class="brush: php;">
body {
  background-color: &lt;?php echo $stylesheet-&gt;getBackgroundColor() ?&gt;;
}
</pre>
<p><em>/lib/model/doctrine/DynamicCSSTable.class.php</em></p>
<pre class="brush: php;">
...
public static function getByIdentifier($identifier)
{
  return $this-&gt;createQuery('c')
    -&gt;addWhere('c.identifier = ?', $identifier)-&gt;fetchOne();
}
...
</pre>
<p>Now you can add your dynamic style sheet to the view.  Here is an example:</p>
<p><em>/apps/frontend/config/view.yml</em></p>
<pre class="brush: css;">
default:
  ...
  stylesheets: [/dynamiccss/main.css: { raw_name: true }]
  ...
</pre>
<p>That &#8220;raw_name&#8221; option allows you to override the typical way of creating an asset&#8217;s file name.  </p>
<p>Now whenever someone edits the background color for the &#8220;main&#8221; style sheet, from the database, the background color can change.</p>
<p>You&#8217;ll still need to add an interface for editing the background color (or however many other options you add).  That is up to you.</p>
<p>Complaints?  Pointers?  Thought of a better way?</p>
<p>Please post.</p>
<p><a href="http://api.tweetmeme.com/share?url=http://jonocode.wordpress.com/2009/08/12/create-a-dynamic-css-module-in-symfony-1-2-fast"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://jonocode.wordpress.com/2009/08/12/create-a-dynamic-css-module-in-symfony-1-2-fast" height="61" width="51" /></a> </p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jonocode.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jonocode.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jonocode.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jonocode.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jonocode.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jonocode.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jonocode.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jonocode.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jonocode.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jonocode.wordpress.com/111/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=111&subd=jonocode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jonocode.wordpress.com/2009/08/12/create-a-dynamic-css-module-in-symfony-1-2-fast/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d13feaa45035e90bbbf6754ea3de3eb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">developerstravels</media:title>
		</media:content>

		<media:content url="http://api.tweetmeme.com/imagebutton.gif?url=http://jonocode.wordpress.com/2009/08/12/create-a-dynamic-css-module-in-symfony-1-2-fast" medium="image" />
	</item>
		<item>
		<title>How to add image uploading to your forms with Symfony 1.2 and Doctrine, from beginning to end</title>
		<link>http://jonocode.wordpress.com/2009/07/31/how-to-add-image-uploading-to-your-forms-with-symfony-1-2-and-doctrine-from-beginning-to-end/</link>
		<comments>http://jonocode.wordpress.com/2009/07/31/how-to-add-image-uploading-to-your-forms-with-symfony-1-2-and-doctrine-from-beginning-to-end/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 16:59:24 +0000</pubDate>
		<dc:creator>jjmontgo</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[File Uploads]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Symfony 1.2]]></category>
		<category><![CDATA[sfThumbnailPlugin]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[sfValidatorFile]]></category>
		<category><![CDATA[sfWidgetFormInputFileEditable]]></category>

		<guid isPermaLink="false">http://jonocode.wordpress.com/?p=97</guid>
		<description><![CDATA[I&#8217;m still very new to Symfony 1.2 and its form framework.  Reading through documentation, discussion forums and blog posts, I couldn&#8217;t find a tutorial which had everything I needed in an image upload.  Having finished an image upload for the first time, I decided to write such a tutorial.
This tutorial requires Symfony 1.2, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=97&subd=jonocode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;m still very new to Symfony 1.2 and its form framework.  Reading through documentation, discussion forums and blog posts, I couldn&#8217;t find a tutorial which had everything I needed in an image upload.  Having finished an image upload for the first time, I decided to write such a tutorial.</p>
<p>This tutorial requires Symfony 1.2, the Doctrine ORM plugin and the PHP GD library.  You should already have all of these elements installed, and be familiar with them.</p>
<p>We&#8217;ll start at the beginning.  I&#8217;m going to make an uploader for a background image to attach to a Website model.  Make sure you have a field in your model to store the image file name:</p>
<pre class="brush: css;">
Website:
  columns:
    background_image:  string(255)
</pre>
<p>And rebuild your model:</p>
<pre class="brush: css;">
symfony doctrine:build-all-reload
</pre>
<p>Now open the form class generated from your schema.</p>
<p>You&#8217;re going to add a widget and a validator for the image upload.  The widget will also allow the user to view the image after it has been uploaded, and delete it if necessary.  The validator will make sure the image upload is not required (it is required by default).  There is also a second validator, sfValidatorPass, because the widget we are using adds a checkbox widget giving the user the option to delete the file.</p>
<p>You&#8217;ll also override the doSave() method and updateObject() methods.  The doSave() method will handle the upload (if there is one), create a new file name for the image, and save the image both to the file system and the background_image field automatically.  Since the background_image field is automatically set with the full path of the file, you will use updateObject() to remove the path and just store the file name.  If you move your project to another system, the file path will change and so we want to store just the file name.</p>
<p>Also in doSave(), you will handle the case where the user has checked off the &#8220;delete image&#8221; checkbox, which is automatically named background_image_delete.</p>
<p>Here is the code so far under <em>lib/form/doctrine/WebsiteForm.class.php</em>:</p>
<pre class="brush: php;">
class WebsiteForm extends BaseWebsiteForm
{
  public function configure()
  {
    $this-&gt;widgetSchema['background_image'] = new sfWidgetFormInputFileEditable(array(
      'file_src' =&gt; '/'.basename(sfConfig::get('sf_upload_dir')).'/'.$this-&gt;getObject()-&gt;getBackgroundImage(),
      'is_image' =&gt; true,
      'edit_mode' =&gt; strlen($this-&gt;getObject()-&gt;getBackgroundImage()) &gt; 0,
      'template'  =&gt; '
&lt;div&gt;%file%
%input%
%delete% %delete_label%&lt;/div&gt;
'
    ));

    $this-&gt;validatorSchema['background_image'] = new sfValidatorFile(array(
      'required' =&gt; false,
      'mime_types' =&gt; 'web_images'
    ));
    $this-&gt;validatorSchema['background_image_delete'] = new sfValidatorPass();
  }

  protected function doSave ( $con = null )
  {
    $upload = $this-&gt;getValue('background_image');

    if ( $upload )
    {
      $filename = sha1($upload-&gt;getOriginalName().microtime().rand()).$upload-&gt;getExtension($upload-&gt;getOriginalExtension());
      $filepath = sfConfig::get('sf_upload_dir').'/'.$filename;

      $oldfilepath = sfConfig::get('sf_upload_dir').'/'.$this-&gt;getObject()-&gt;getBackgroundImage();
      if ( file_exists($oldfilepath) )
      {
        unlink($oldfilepath);
      }

      $upload-&gt;save($filepath);
    }

    $delete = $this-&gt;getValue('background_image_delete');
    if ( $delete )
    {
      $filename = $this-&gt;getObject()-&gt;getBackgroundImage();
      $filepath = sfConfig::get('sf_upload_dir').'/'.$filename;
      @unlink($filepath);
      $this-&gt;getObject()-&gt;setBackgroundImage(null);
    }

    return parent::doSave($con);
  }

  public function updateObject($values = null)
  {
    $object = parent::updateObject($values);
    $object-&gt;setBackgroundImage(str_replace(sfConfig::get('sf_upload_dir').'/', '', $object-&gt;getBackgroundImage()));
    return $object;
  }

}
</pre>
<p>This should work well for the most part.  But what if the image is 2000 pixels in width?  It will be very disruptive to display such a large image.</p>
<p>That&#8217;s where <a href="http://www.symfony-project.org/plugins/sfThumbnailPlugin">sfThumbnailPlugin</a> comes in.</p>
<p>Install the plugin if you haven&#8217;t already done so:</p>
<pre class="brush: bash;">
$ symfony plugin:install sfThumbnailPlugin
$ php symfony cc
</pre>
<p>Now create a new directory to store your thumbnails:</p>
<pre class="brush: bash;">
$ mkdir /web/uploads/thumbnails
</pre>
<p>You&#8217;ll probably want to use this directory in other modules or applications in your project.  Add a new setting called sf_thumbnail_dir in your project configuration:</p>
<p><em>config/ProjectConfiguration.class.php</em></p>
<pre class="brush: php;">
...
class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    ...
    sfConfig::set('sf_thumbnail_dir', sfConfig::get('sf_upload_dir').'/thumbnails');
    ...
  }
}
</pre>
<p>Now all that&#8217;s left to do is create and store the thumbnail from the doSave() method of your form class, and make sure that your form displays the thumbnail and not the source image in your configure() method.</p>
<p>Modify the widget settings so that it displays the thumbnail.  Note that I&#8217;ve &#8230;&#8217;d most of the parts that don&#8217;t change:</p>
<p><em>lib/form/doctrine/WebsiteForm.class.php</em></p>
<pre class="brush: php;">
class WebsiteForm extends BaseWebsiteForm
{
  public function configure()
  {
    ...
    $this-&gt;widgetSchema['background_image'] = new sfWidgetFormInputFileEditable(array(
      'file_src' =&gt; '/'.basename(sfConfig::get('sf_upload_dir')).'/'.basename(sfConfig::get('sf_thumbnail_dir')).'/'.$this-&gt;getObject()-&gt;getBackgroundImage(),
      'is_image' =&gt; true,
      'edit_mode' =&gt; strlen($this-&gt;getObject()-&gt;getBackgroundImage()) &gt; 0,
      'template'  =&gt; '
&lt;div&gt;%file%
%input%
%delete% %delete_label%&lt;/div&gt;
'
    ));
    ...
  }

  protected function doSave ( $con = null )
  {
    $upload = $this-&gt;getValue('background_image');

    if ( $upload )
    {
      ...
      $thumbnailpath = sfConfig::get('sf_thumbnail_dir').'/'.$filename;
      ...
      $oldthumbnailpath = sfConfig::get('sf_thumbnail_dir').'/'.$this-&gt;getObject()-&gt;getBackgroundImage();
      if ( file_exists($oldthumbnailpath) )
      {
        unlink($oldthumbnailpath);
      }

      ...
      $thumbnail = new sfThumbnail(150, 150, true, true, 75, 'sfGDAdapter');
      $thumbnail-&gt;loadFile($filepath);
      $thumbnail-&gt;save($thumbnailpath);
    }

    $delete = $this-&gt;getValue('background_image_delete');

    if ( $delete )
    {
      ...
      $thumbnailpath = sfConfig::get('sf_thumbnail_dir').'/'.$filename;
      @unlink($thumbnailpath);
      ...
    }
  }

  ...

}
</pre>
<p>And that&#8217;s all there is to it.  Note that there is no template file here because the form framework handles the view of the form inputs.</p>
<p>Questions?  Complaints?  Leave a comment.</p>
<p><a href="http://api.tweetmeme.com/share?url=http://jonocode.wordpress.com/2009/07/31/how-to-add-image-uploading-to-your-forms-with-symfony-1-2-and-doctrine-from-beginning-to-end/"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://jonocode.wordpress.com/2009/07/31/how-to-add-image-uploading-to-your-forms-with-symfony-1-2-and-doctrine-from-beginning-to-end/" height="61" width="51" /></a> </p>
<p>Here are some related resources:</p>
<ul>
<li><a href="http://www.symfony-project.org/forms/1_2/en/A-Widgets#chapter_a_sub_sfwidgetforminputfileeditable">sfWidgetFormInputFileEditable documentation</a></li>
<li><a href="http://www.symfony-project.org/forms/1_2/en/B-Validators#chapter_b_sub_sfvalidatorfile">sfValidatorFile documentation</a></li>
<li><a href="http://www.symfony-project.org/plugins/sfThumbnailPlugin/1_5_6?tab=plugin_readme">sfThumbnailPlugin readme</a></li>
</ul>
<p>Here are some other posts you might be interested in:</p>
<ul>
<li><a href="http://jonocode.wordpress.com/2009/07/11/adding-sf_guard_user_profile-to-the-sfdoctrineguardplugin/">Adding to the sfDoctrineGuardPlugin</a></li>
<li><a href="http://jonocode.wordpress.com/2009/06/22/how-to-secure-fckeditor-against-unauthorized-access-in-a-symfony-application/">How to secure FCKEditor against unauthorized access in a Symfony application</a></li>
<li><a href="http://jonocode.wordpress.com/2009/07/22/table-level-behaviors-will-remove-global-behaviors-in-doctrine-schemas/">Table-level behaviors will remove global behaviors in Doctrine schemas</a></li>
</ul>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jonocode.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jonocode.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jonocode.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jonocode.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jonocode.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jonocode.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jonocode.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jonocode.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jonocode.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jonocode.wordpress.com/97/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=97&subd=jonocode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jonocode.wordpress.com/2009/07/31/how-to-add-image-uploading-to-your-forms-with-symfony-1-2-and-doctrine-from-beginning-to-end/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d13feaa45035e90bbbf6754ea3de3eb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">developerstravels</media:title>
		</media:content>

		<media:content url="http://api.tweetmeme.com/imagebutton.gif?url=http://jonocode.wordpress.com/2009/07/31/how-to-add-image-uploading-to-your-forms-with-symfony-1-2-and-doctrine-from-beginning-to-end/" medium="image" />
	</item>
		<item>
		<title>Table-level behaviors will remove global behaviors in Doctrine schemas</title>
		<link>http://jonocode.wordpress.com/2009/07/22/table-level-behaviors-will-remove-global-behaviors-in-doctrine-schemas/</link>
		<comments>http://jonocode.wordpress.com/2009/07/22/table-level-behaviors-will-remove-global-behaviors-in-doctrine-schemas/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 00:44:24 +0000</pubDate>
		<dc:creator>jjmontgo</dc:creator>
				<category><![CDATA[Behaviors]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[Symfony 1.2]]></category>

		<guid isPermaLink="false">http://jonocode.wordpress.com/?p=91</guid>
		<description><![CDATA[Here is something to watch out for.  If you define global behaviors in your schema, and then define table-level behaviors, the global behavior will be removed (unless you declare it again on the table level).
Here is a quick example:

actAs: [Timestampable]

Program:
  actAs:
    Sluggable:
      fields: [name]
  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=91&subd=jonocode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Here is something to watch out for.  If you define global behaviors in your schema, and then define table-level behaviors, the global behavior will be removed (unless you declare it again on the table level).</p>
<p>Here is a quick example:</p>
<pre class="brush: css;">
actAs: [Timestampable]

Program:
  actAs:
    Sluggable:
      fields: [name]
  columns:
    name: string(255)
    user_id: integer(4)
  relations:
    sfGuardUser:
      foreignType: many
      type: one
      local: user_id
      foreign: id
</pre>
<p>For a short while I couldn&#8217;t figure out why the created_at and updated_at fields weren&#8217;t showing up in the Program table.  Then I realized that it was removed at the table level, and I had to add it in again.</p>
<p>The official documentation does not mention this:</p>
<p><a href="http://www.symfony-project.org/doctrine/1_2/en/04-Schema-Files#chapter_04_global_schema_information">http://www.symfony-project.org/doctrine/1_2/en/04-Schema-Files#chapter_04_global_schema_information</a></p>
<p>Hopefully this will save you 15 minutes of scratching your head.</p>
<p>Here is more information on Symfony 1.2 and doctrine:</p>
<p><a href="http://www.symfony-project.org/doctrine/1_2/en/04-Schema-Files">http://www.symfony-project.org/doctrine/1_2/en/04-Schema-Files</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jonocode.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jonocode.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jonocode.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jonocode.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jonocode.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jonocode.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jonocode.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jonocode.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jonocode.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jonocode.wordpress.com/91/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=91&subd=jonocode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jonocode.wordpress.com/2009/07/22/table-level-behaviors-will-remove-global-behaviors-in-doctrine-schemas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d13feaa45035e90bbbf6754ea3de3eb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">developerstravels</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Symfony filters and CSS to present a design in-context</title>
		<link>http://jonocode.wordpress.com/2009/07/18/using-symfony-filters-and-css-to-present-a-design-in-context/</link>
		<comments>http://jonocode.wordpress.com/2009/07/18/using-symfony-filters-and-css-to-present-a-design-in-context/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 19:00:40 +0000</pubDate>
		<dc:creator>jjmontgo</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Filters]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony 1.0]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://jonocode.wordpress.com/?p=85</guid>
		<description><![CDATA[This post assumes you have some experience with Symfony 1.0.
At my work I needed to create several different versions of the same site.  This mainly entailed changing background images to get a slightly different look and feel, and changing the content category, depending on a request parameter.
For this tutorial, I will use the company [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=85&subd=jonocode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>This post assumes you have some experience with Symfony 1.0.</p>
<p>At my work I needed to create several different versions of the same site.  This mainly entailed changing background images to get a slightly different look and feel, and changing the content category, depending on a request parameter.</p>
<p>For this tutorial, I will use the company I work for as an example.  <a href="http://www.momentumitgroup.com">Momentum IT Group</a> has two distinct divisions: ELearning and Web.  So let&#8217;s say I wanted to make slight design changes depending on which division I&#8217;m looking at.</p>
<p>We&#8217;ll start where all things Symfony begin: with the routes.  Open up <code>apps/frontend/config/routing.yml</code> and enter the following:</p>
<pre class="brush: css;">
division_page:
  url:               /:division/:slug
  param:          { module: cms, action: display }
  requirements: { division: elearning|web }
</pre>
<p>I leave the cms module for you to implement.  The display action would take a unique slug as a key to look up the page content from the database for display.</p>
<p>In this route, the division is required to be either elearning or web, and these two options will be used to display a different background design (and possibly select from a different content category in your cms module). </p>
<p>The next step is to implement the switch which determines which background to apply, if any.  You can always write this code in your cms module, but you may have other modules other than the cms module which need to change design elements depending on which division the user is viewing.  To handle this situation, you can create a filter.</p>
<p>A filter is applied once for each request.  Start by opening <code>apps/frontend/config/filters.yml</code> and adding a new filter class:</p>
<pre class="brush: css;">
rendering:    ~
web_debug: ~
security:     ~

# generally, you will want to insert your own filters here
cssFilter:
  class:       cssFilter

cache:       ~
common:    ~
flash:         ~
execution:  ~
</pre>
<p>Create the filter class in <code>apps/frontend/lib/cssFilter.class.php</code>:</p>
<pre class="brush: php;">
&lt;?php

class cssFilter extends sfFilter
{
  public function execute($filterChain)
  {
    if ( $this-&gt;isFirstCall())
    {
      $response = $this-&gt;getContext()-&gt;getResponse();
      switch ( sfContext::getInstance()-&gt;getRequest()-&gt;getParameter('division') )
      {
        case 'elearning':
          $response-&gt;addStylesheet('elearning', 'last');
        break;
        case 'web':
          $response-&gt;addStylesheet('web', 'last');
        break;
      }
    }
  }
}
</pre>
<p>Make sure you place two new CSS files in your <code>web/css</code> directory.  </p>
<p>For this example, they are elearning.css and web.css.  They will be the last css files in your HTML header and will override your main.css where needed.  So, you might override a background image like so:</p>
<p><strong><code>web/css/main.css</code></strong></p>
<pre class="brush: css;">
body {
  background: url(../images/background.jpg) no-repeat top left;
}
</pre>
<p><strong><code>web/css/elearning.css</code></strong></p>
<pre class="brush: css;">
body {
  background-image: url(../images/elearning.jpg);
}
</pre>
<p>Now if you direct your browser to <code>[your_site]/elearning/[page_slug]</code>, you will have taken advantage of CSS cascading and Symfony filters to present a slightly different design depending on the context.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jonocode.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jonocode.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jonocode.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jonocode.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jonocode.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jonocode.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jonocode.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jonocode.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jonocode.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jonocode.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=85&subd=jonocode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jonocode.wordpress.com/2009/07/18/using-symfony-filters-and-css-to-present-a-design-in-context/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d13feaa45035e90bbbf6754ea3de3eb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">developerstravels</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding to the sfDoctrineGuardPlugin</title>
		<link>http://jonocode.wordpress.com/2009/07/11/adding-sf_guard_user_profile-to-the-sfdoctrineguardplugin/</link>
		<comments>http://jonocode.wordpress.com/2009/07/11/adding-sf_guard_user_profile-to-the-sfdoctrineguardplugin/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 22:46:13 +0000</pubDate>
		<dc:creator>jjmontgo</dc:creator>
				<category><![CDATA[ORM]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony 1.2]]></category>
		<category><![CDATA[YAML]]></category>
		<category><![CDATA[sfDoctrineGuardPlugin]]></category>

		<guid isPermaLink="false">http://jonocode.wordpress.com/?p=70</guid>
		<description><![CDATA[Here are some excellent resources for working with sfDoctrineGuardPlugin:
Plugin page on symfony (README is possibly out of date)
http://www.symfony-project.org/plugins/sfDoctrineGuardPlugin
Tutorial on how to add a profile to work with sfDoctrineGuardPlugin
http://www.symfony-project.org/blog/2008/11/12/call-the-expert-customizing-sfdoctrineguardplugin
Tutorial on how to add a registration module
http://www.symfony-project.org/blog/2008/12/03/call-the-expert-simple-registration-with-sfdoctrineguardplugin
First of all, the schema code in the documentation for sfDoctrineGuard appears to be old:
(be mindful of the lack of proper [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=70&subd=jonocode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Here are some excellent resources for working with sfDoctrineGuardPlugin:</p>
<p style="padding-left:30px;"><strong>Plugin page on symfony (README is possibly out of date)</strong><br />
<a href="http://www.symfony-project.org/plugins/sfDoctrineGuardPlugin">http://www.symfony-project.org/plugins/sfDoctrineGuardPlugin</a></p>
<p style="padding-left:30px;"><strong>Tutorial on how to add a profile to work with sfDoctrineGuardPlugin</strong><br />
<a href="http://www.symfony-project.org/blog/2008/11/12/call-the-expert-customizing-sfdoctrineguardplugin">http://www.symfony-project.org/blog/2008/11/12/call-the-expert-customizing-sfdoctrineguardplugin</a></p>
<p style="padding-left:30px;"><strong>Tutorial on how to add a registration module</strong><br />
<a href="http://www.symfony-project.org/blog/2008/12/03/call-the-expert-simple-registration-with-sfdoctrineguardplugin">http://www.symfony-project.org/blog/2008/12/03/call-the-expert-simple-registration-with-sfdoctrineguardplugin</a></p>
<p>First of all, the schema code in the documentation for sfDoctrineGuard appears to be old:</p>
<p>(be mindful of the lack of proper YAML spacing; I haven&#8217;t figured out how to incorporate code into wordpress.com posts yet)</p>
<pre class="brush: css;">
sf_guard_user_profile:
_attributes: { phpName: sfGuardUserProfile }
id:
user_id:     { type: integer, foreignTable: sf_guard_user, foreignReference: id, required: true, onDelete: cascade }
first_name:  varchar(20)
last_name:   varchar(20)
birthday:    date
</pre>
<p>I replaced it with:</p>
<pre class="brush: css;">
sfGuardUserProfile:
columns:
user_id:     { type: integer, notnull: true, required: true }
first_name:  string(20)
last_name:   string(20)
email:       string(75)
relations:
sfGuardUser: { local: user_id, foreign: id, onDelete: CASCADE }
</pre>
<p>This schema could be parsed by Doctrine in Symfony 1.2.  I ran the <tt>symfony doctrine:build-all-reload</tt> task again.  However it coughed up an error from MySQL:</p>
<p><code><br />
SQLSTATE[HY000]: General error: 1005 Can't create table 'register.#sql-ae0_25'<br />
(errno: 150). Failing Query: ALTER TABLE sf_guard_user_profile ADD FOREIGN KEY<br />
(user_id) REFERENCES sf_guard_user(id) ON DELETE CASCADE<br />
</code></p>
<p>This seems to be a problem with the field definition.  It has to do with user_id being integer (bigint in the SQL), and the id field in the plugin&#8217;s schema set to integer(4).  Others have run into this error:</p>
<p><a href="http://forums.mysql.com/read.php?22,19755,19755#msg-19755">http://forums.mysql.com/read.php?22,19755,19755#msg-19755</a></p>
<p>Anyhow, I changed the definition for user_id to be the primary key.  This is how it should be anyway; each user should only have one profile.</p>
<pre class="brush: css;">
sfGuardUserProfile:
columns:
user_id:     { type: integer(4), primary: true }
...etc...
</pre>
<p>I ran <tt>symfony doctrine:build-all-reload</tt> again, and everything was fine&#8230;</p>
<p>Until I started using fixtures to load some default users and profiles:</p>
<pre class="brush: css;">
sfGuardUser:
sgu_admin:
username:       admin
password:       mr9o1ob7
is_super_admin: true
normal_user:
username:       user
password:       password
is_super_admin: false&lt;/code&gt;

sfGuardUserProfile:
sgup_admin:
sfGuardUser:    sgu_admin
first_name:     Jonathan
last_name:      Montgomery
email:          jjmontgo@gmail.com
sgup_user:
sfGuardUser:    normal_user
first_name:     Normal
last_name:      User
email:          noone@gmail.com

sfGuardPermission:
sgp_admin:
name:           admin
description:    Administrator permission

sfGuardGroup:
sgg_admin:
name:           admin
description:    Administrator group

sfGuardGroupPermission:
sggp_admin:
sfGuardGroup:       sgg_admin
sfGuardPermission:  sgp_admin

sfGuardUserGroup:
sgug_admin:
sfGuardGroup:       sgg_admin
sfGuardUser:        sgu_admin
</pre>
<p>This loaded to the database with user_id set to 0 in the user profile.</p>
<p>I tinkered around a bit more, altered the sfGuardUser relation under the profile schema (which didn&#8217;t seem to help), and eventually removed the primary key from user_id.</p>
<p>That worked.  I&#8217;m not sure why.  I don&#8217;t see why sfGuardUserProfile should have its own id field as a primary key.  Please comment on this if you know the answer.</p>
<p>Here is my final sfGuardUserProfile schema:</p>
<pre class="brush: css;">
sfGuardUserProfile:
actAs: [Timestampable]
columns:
user_id:
type: integer(4)
first_name:  string(20)
last_name:   string(20)
email:       string(75)
relations:
sfGuardUser:
local:     user_id
foreign:   id
type:      one
foreignType: one
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jonocode.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jonocode.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jonocode.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jonocode.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jonocode.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jonocode.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jonocode.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jonocode.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jonocode.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jonocode.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jonocode.wordpress.com&blog=8189248&post=70&subd=jonocode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jonocode.wordpress.com/2009/07/11/adding-sf_guard_user_profile-to-the-sfdoctrineguardplugin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d13feaa45035e90bbbf6754ea3de3eb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">developerstravels</media:title>
		</media:content>
	</item>
	</channel>
</rss>