<?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>OXT blog &#187; symfony</title>
	<atom:link href="http://blog.o-x-t.com/tag/symfony/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.o-x-t.com</link>
	<description>"People say nothing is impossible, but I do nothing every day." - Whinnie The Pooh</description>
	<lastBuildDate>Wed, 25 Aug 2010 19:18:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Symfony Doctrine Sluggable &#8211; rebuilding empty slugs</title>
		<link>http://blog.o-x-t.com/2010/08/25/symfony-doctrine-sluggable-rebuilding-empty-slugs/</link>
		<comments>http://blog.o-x-t.com/2010/08/25/symfony-doctrine-sluggable-rebuilding-empty-slugs/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 19:18:05 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[sluggable]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/?p=244</guid>
		<description><![CDATA[If you add slugs with Sluggable behaviour in the middle of your project you&#8217;ll have empty slugs for all old records. To fix it you need to save your models via symfony, slugs will be built automatically. You can automate it with help of this simple task: class buildSlugTask extends sfBaseTask &#123; protected function configure&#40;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>If you add slugs with Sluggable behaviour in the middle of your project you&#8217;ll have empty slugs for all old records. To fix it you need to save your models via symfony, slugs will be built automatically.</p>
<p>You can automate it with help of this simple task:<br />
<span id="more-244"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> buildSlugTask <span style="color: #000000; font-weight: bold;">extends</span> sfBaseTask
<span style="color: #009900;">&#123;</span>
  protected <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addArguments</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #000000; font-weight: bold;">new</span> sfCommandArgument<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'model'</span><span style="color: #339933;">,</span> sfCommandArgument<span style="color: #339933;">::</span><span style="color: #004000;">REQUIRED</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #000000; font-weight: bold;">new</span> sfCommandArgument<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'field'</span><span style="color: #339933;">,</span> sfCommandArgument<span style="color: #339933;">::</span><span style="color: #004000;">REQUIRED</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Slug source field'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOptions</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #000000; font-weight: bold;">new</span> sfCommandOption<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'application'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> sfCommandOption<span style="color: #339933;">::</span><span style="color: #004000;">PARAMETER_REQUIRED</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The application name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #000000; font-weight: bold;">new</span> sfCommandOption<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'env'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> sfCommandOption<span style="color: #339933;">::</span><span style="color: #004000;">PARAMETER_REQUIRED</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The environment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'dev'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #000000; font-weight: bold;">new</span> sfCommandOption<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'connection'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> sfCommandOption<span style="color: #339933;">::</span><span style="color: #004000;">PARAMETER_REQUIRED</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The connection name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'doctrine'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">namespace</span>        <span style="color: #339933;">=</span> <span style="color: #0000ff;">'oxt'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span>             <span style="color: #339933;">=</span> <span style="color: #0000ff;">'buildSlug'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">briefDescription</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Rebuild empty slug'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">detailedDescription</span> <span style="color: #339933;">=</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;EOF
The [buildSlug|INFO] task rebuilds empty slugs.
Call it with:
&nbsp;
  [php symfony buildSlug|INFO]
EOF</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  protected <span style="color: #000000; font-weight: bold;">function</span> execute<span style="color: #009900;">&#40;</span><span style="color: #000088;">$arguments</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// initialize the database connection</span>
    <span style="color: #000088;">$databaseManager</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfDatabaseManager<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">configuration</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$connection</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$databaseManager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDatabase</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'connection'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arguments</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'model'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m.slug IS NULL'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//cheat doctrine to re-save our model</span>
      <span style="color: #000088;">$field_value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arguments</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arguments</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arguments</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field_value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Call it with model name and slug field name. If you have slug built from several fields you can pass any of them.<br />
E.g.:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>symfony oxt:buildSlug Record title</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2010/08/25/symfony-doctrine-sluggable-rebuilding-empty-slugs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony, propel and long running scripts</title>
		<link>http://blog.o-x-t.com/2009/11/28/symfony-propel-and-long-running-scripts/</link>
		<comments>http://blog.o-x-t.com/2009/11/28/symfony-propel-and-long-running-scripts/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 15:25:18 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/?p=228</guid>
		<description><![CDATA[For long running scripts in symfony with propel ORM you may experience problems with memory usage. To avoid them make sure to disable propel instance caching by calling this code at the beginning of the script: Propel::disableInstancePooling&#40;&#41;; Propel by default caches in memory all fetched database objects. That means that for scripts with extensive db [...]]]></description>
			<content:encoded><![CDATA[<p>For long running scripts in symfony with propel ORM you may experience problems with memory usage. To avoid them make sure to disable propel instance caching by calling this code at the beginning of the script:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Propel<span style="color: #339933;">::</span><span style="color: #004000;">disableInstancePooling</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Propel by default caches in memory all fetched database objects. That means that for scripts with extensive db usage or long running time you may hit php <code>memory_limit</code> sooner or later.<br />
Starting with propel 1.3 shipped with symfony 1.3 and 1.4 which are about to be released you&#8217;ll be able to disable instance pooling in database yaml config.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2009/11/28/symfony-propel-and-long-running-scripts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>symfony: sfValidatorFile &#8211; invalid mime type (text/plain) for PNG images</title>
		<link>http://blog.o-x-t.com/2009/07/27/symfony-sfvalidatorfile-invalid-mime-type-textplain-for-png-images/</link>
		<comments>http://blog.o-x-t.com/2009/07/27/symfony-sfvalidatorfile-invalid-mime-type-textplain-for-png-images/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 13:47:02 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/?p=217</guid>
		<description><![CDATA[On some systems sfValidatorFile may give you an error when trying to upoad PNG images. It says that it has invalid mime type &#8211; text/plain, though you have 'mime_types' = 'web_images' and other image formats work well. It may be caused by wrong result from mime_content_type() function. To check if it&#8217;s your case create simple [...]]]></description>
			<content:encoded><![CDATA[<p>On some systems <code>sfValidatorFile</code> may give you an error when trying to upoad PNG images. It says that it has invalid mime type &#8211; text/plain, though you have <code>'mime_types' = 'web_images'</code> and other image formats work well.</p>
<p>It may be caused by wrong result from <code>mime_content_type()</code> function. To check if it&#8217;s your case create simple php script with just one line:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #990000;">mime_content_type</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'path_to_your_png_image'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If it will give you <code>text/plain</code> then you have three options:</p>
<ol>
<li>Upgrade your PHP to 5.3.0, though I doubt it&#8217;s available for most *nix distributions at this time.</li>
<li>Install PECL package <a href="http://pecl.php.net/package/Fileinfo">Fileinfo</a>.</li>
<li>The easiest, modify form class.</li>
</ol>
<p>In first two options <code>sfValidatorFile</code> will use <code>finfo_open</code> function prior to <code>mime_content_type</code> and it should give correct results for PNG image. However, upgrading PHP or installing PECL package isn&#8217;t always possible.</p>
<p>The simplest way to fix this bug is to apply small modifications to your form class, just reorder mime type guessers:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorFile<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'required'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'path'</span>       <span style="color: #339933;">=&gt;</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_upload_dir'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/directory'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'mime_types'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'web_images'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mime_type_guessers'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'guessFromFileinfo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'guessFromFileBinary'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'guessFromMimeContentType'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this case validator will first try <code>fileinfo</code> (which should be available since PHP 5.3.0), then <code>'file -bi'</code> which should work correctly on *nix platform and only if both failed it will use <code>mime_content_type</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2009/07/27/symfony-sfvalidatorfile-invalid-mime-type-textplain-for-png-images/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>symfony l10n &#8211; going further</title>
		<link>http://blog.o-x-t.com/2009/04/19/symfony-l10n-going-further/</link>
		<comments>http://blog.o-x-t.com/2009/04/19/symfony-l10n-going-further/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 20:39:16 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[l10n]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/?p=180</guid>
		<description><![CDATA[As you may know symfony offers localized objects out of the box. It gives you an easy way to have different data for different cultures. Sometimes it is not enough. I needed two localized version of website but with completely different content &#8211; everything including users, admin and super admin. Both version were supposed to [...]]]></description>
			<content:encoded><![CDATA[<p>As you may know symfony offers localized objects out of the box. It gives you an easy way to have different data for different cultures.</p>
<p>Sometimes it is not enough. I needed two localized version of website but with completely different content &#8211; everything including users, admin and super admin. Both version were supposed to run under the same domain and to be distinguished just by locale part in the url. I was too lazy and didn&#8217;t want to copy applications or projects (moreover, it is a problem in the future, you&#8217;ll have to modify each copy). So, I decided to use different databases with exact schema for different cultures.</p>
<p>Here&#8217;s guide how to implement this.<br />
<span id="more-180"></span></p>
<p>First of all, I need to extract locale parameter from the url. That is easy, you&#8217;ll find it in the symfony docs.<br />
Routes config (routing.yml):</p>
<pre>
action:
  url:   /:locale/:module/:action/*
  requirements: {locale: nl|be}
</pre>
<p>I needed only NL and BE locales.</p>
<p>Then, you need to setup two databases. I was using symfony 1.1 with doctrine, but it should be possible for 1.2 also and propel or whatever ORM you are convenient with. Doctrine is able to work with multiple connections. However, I don&#8217;t need multiple connections. I need them both defined but I need only one current connection for every request. So I&#8217;m defining two connections but not specifying any binding to connection in model schema.<br />
Databases config (databases.yml):</p>
<pre>
all:
  belgium:
    class:          sfDoctrineDatabase
    param:
      dsn:          mysql://user_be:pass_be@host_be/db_be
  primary:
    class:          sfDoctrineDatabase
    param:
      dsn:          mysql://user_nl:pass_nl@host_nl/db_nl
</pre>
<p>If you check your application at this moment it will use connection last defined.</p>
<p>So, now I only need to switch between these connections. I can do it with filters.<br />
filters.yml:</p>
<pre>
rendering: ~
security:  ~
l10n:
  class: l10nFilter
cache:     ~
common:    ~
execution: ~
</pre>
<p>And the filter itself:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> l10nFilter <span style="color: #000000; font-weight: bold;">extends</span> sfFilter 
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> execute<span style="color: #009900;">&#40;</span><span style="color: #000088;">$filterChain</span><span style="color: #009900;">&#41;</span> 
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isFirstCall</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$locale</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'locale'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #666666; font-style: italic;">//sanitize locale</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'locale'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$locale</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$connection</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$locale</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'be'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'belgium'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'primary'</span><span style="color: #339933;">;</span>
      Doctrine_Manager<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCurrentConnection</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$connection</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$filterChain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That&#8217;s it.</p>
<p>The small issue is that if you are going to use symfony db tasks (e.g. migrations or data population) you&#8217;ll need to set additional environments:<br />
databases.yml:</p>
<pre>
prod_be:
  primary:
    class:          sfDoctrineDatabase
    param:
      dsn:          mysql://user_be:pass_be@host_be/db_be
prod_nl:
  primary:
    class:          sfDoctrineDatabase
    param:
      dsn:          mysql://user_nl:pass_nl@host_nl/db_nl
</pre>
<p>And call your tasks twice for each pseudo-environment by adding &#8211;env=prod_be or &#8211;env=prod_nl.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2009/04/19/symfony-l10n-going-further/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problems with index module routing in symfony</title>
		<link>http://blog.o-x-t.com/2008/11/26/problems-with-index-module-routing-in-symfony/</link>
		<comments>http://blog.o-x-t.com/2008/11/26/problems-with-index-module-routing-in-symfony/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 11:48:12 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/?p=124</guid>
		<description><![CDATA[I was working on simple symfony website consisting of just one application and one module. Naturally, I wasn&#8217;t too creative and choose &#8216;frontend&#8217; as application name and &#8216;index&#8217; for module name. When I started to test it on production, it wasn&#8217;t working at all except default action. It was giving me 404 error. After spending [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on simple symfony website consisting of just one application and one module. Naturally, I wasn&#8217;t too creative and choose &#8216;frontend&#8217; as application name and &#8216;index&#8217; for module name. When I started to test it on production, it wasn&#8217;t working at all except default action. It was giving me 404 error.<br />
After spending some time debugging and logging symfony and mod_rewrite I&#8217;ve found out the problem. Rewrite rule was sending me to /index.php/actionname instead of index.php/index/actionname.<br />
The problem was in apache option MultiViews, as soon as I removed it everything started to work as expected. This option tells webserver to search for foo/filename.* if foo/filename wasn&#8217;t found.<br />
I had this option enabled in my default virtual host config in my apache distribution and I had never paid any attention to it before.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2008/11/26/problems-with-index-module-routing-in-symfony/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>symfony admin generator &#8211; populating create form from filters</title>
		<link>http://blog.o-x-t.com/2008/10/05/symfony-admin-generator-populating-create-form-from-filters/</link>
		<comments>http://blog.o-x-t.com/2008/10/05/symfony-admin-generator-populating-create-form-from-filters/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 12:24:23 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/?p=90</guid>
		<description><![CDATA[symfony has basic CRUD-like admin generator, which allows you to create controls for filtering list results. Naturally, if you have filtered list and press &#8216;create&#8217; button it would be nice to have new form with populated from filter form fields. Here&#8217;s basic idea how to do it. In my example I have Work entity which [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.symfony-project.org">symfony</a> has basic CRUD-like admin generator, which allows you to create <a href="http://www.symfony-project.org/book/1_1/14-Generators#Filtering%20the%20Results">controls for filtering list results</a>. Naturally, if you have filtered list and press &#8216;create&#8217; button it would be nice to have new form with populated from filter form fields.</p>
<p>Here&#8217;s basic idea how to do it. In my example I have Work entity which has foreign key to Category entity. I have list of works filterable by category id.<br />
To populate category id on work creation form you need to override generated action:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> worksActions <span style="color: #000000; font-weight: bold;">extends</span> autoworksActions
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeEdit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
  	parent<span style="color: #339933;">::</span><span style="color: #004000;">executeEdit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'create'</span><span style="color: #009900;">&#41;</span>
  	<span style="color: #009900;">&#123;</span>
  		<span style="color: #000088;">$filters</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttributeHolder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_admin/work/filters'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filters</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">work</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCategoryId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filters</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	<span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Look into admin generated actions if you want to more clearly understand why we need such code. It is located at cache/admin/dev/modules/autoWorks/actions/actions.class.php</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2008/10/05/symfony-admin-generator-populating-create-form-from-filters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Translating symfony validator yaml configs with xgettext</title>
		<link>http://blog.o-x-t.com/2008/03/09/translating-symfony-validator-yaml-configs-with-xgettext/</link>
		<comments>http://blog.o-x-t.com/2008/03/09/translating-symfony-validator-yaml-configs-with-xgettext/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 18:47:53 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[xgettext]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/2008/03/09/translating-symfony-validator-yaml-configs-with-xgettext/</guid>
		<description><![CDATA[Previously I wrote how to automate routine translation work with xgettext for symfony framework. Unfortunately xgettext cannot parse YAML configs. Obviously you&#8217;ll need to translate at least validator error messages. rgettext is not capable too. I found some solution but I didn&#8217;t like it. I wanted to use PoEdit tool to have possibility for automated [...]]]></description>
			<content:encoded><![CDATA[<p>Previously I wrote how to <a href="/2007/11/16/automating-script-frontend-translation/">automate routine translation work</a> with xgettext for symfony framework. Unfortunately xgettext cannot parse YAML configs. Obviously you&#8217;ll need to translate at least validator error messages. rgettext is not capable too.</p>
<p>I found some <a href="http://trac.symfony-project.com/wiki/HowToGenerateI18NFiles">solution</a> but I didn&#8217;t like it. I wanted to use PoEdit tool to have possibility for automated translation, syncing with sources and easy interface. So I wrote modified task which looks for all validation configs and creates fake php files with messages, which can be parsed by xgettext.</p>
<p>Usage is simple, just copy attached file to symfony/data/tasks in your PEAR directory and run <code>symfony i18n-fake-php app_name</code>. PHP files will be created in validate/ directories. After that you can use xgettext.</p>
<p><a href="http://blog.o-x-t.com/wp-content/uploads/2008/03/sfpakei18nvalidatorsphp.gz" title="sfpakei18nvalidatorsphp.gz">sfpakei18nvalidatorsphp.gz</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2008/03/09/translating-symfony-validator-yaml-configs-with-xgettext/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rsync using checksum in Symfony</title>
		<link>http://blog.o-x-t.com/2008/03/05/rsync-using-checksum-in-symfony/</link>
		<comments>http://blog.o-x-t.com/2008/03/05/rsync-using-checksum-in-symfony/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 09:01:04 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/2008/03/05/rsync-using-checksum-in-symfony/</guid>
		<description><![CDATA[Symfony framework allows easy deployment of the project. All you need to deploy using rsync &#8211; is to type symfony sync production (add go to the command for real deploying). It takes connection parameters from config/properties.ini. However it is using files comparison by size and modification date, default for rsync utility. It isn&#8217;t in symfony [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://symfony-project.com">Symfony</a> framework allows easy deployment of the project. All you need to deploy using rsync &#8211; is to type <code>symfony sync production</code> (add <code>go</code> to the command for real deploying). It takes connection parameters from config/properties.ini.</p>
<p>However it is using files comparison by size and modification date, default for <code>rsync</code> utility. It isn&#8217;t in symfony documentation, but you can easily change rsync parameters to whatever.</p>
<p>Default parameters symfony uses are <code>-azC --exclude-from=config/rsync_exclude.txt --force --delete</code>. To use checksum comparison add the line to [production] in properties.ini:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">parameters</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;-azC --exclude-from=config/rsync_exclude.txt --force --delete --checksum&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2008/03/05/rsync-using-checksum-in-symfony/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
