<?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>Janusz Slota &#187; php</title>
	<atom:link href="http://janusz.slota.name/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://janusz.slota.name/blog</link>
	<description>My home page</description>
	<lastBuildDate>Thu, 08 Dec 2011 09:56:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>How to handle sfError404Exception</title>
		<link>http://janusz.slota.name/blog/2011/12/how-to-handle-sferror404exception/</link>
		<comments>http://janusz.slota.name/blog/2011/12/how-to-handle-sferror404exception/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 18:42:46 +0000</pubDate>
		<dc:creator>Janusz Słota</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony1]]></category>

		<guid isPermaLink="false">http://janusz.slota.name/blog/?p=227</guid>
		<description><![CDATA[The problem: Let&#8217;s say you need to migrate old website to you new Symfony app. You want to keep all old links working. When they do not match the new link scheme, you want to redirect with 301 (or 302) to correct page in the new URL scheme. All these can be managed via backend [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The problem:</strong></p>
<p>Let&#8217;s say you need to migrate old website to you new Symfony app. You want to keep all old links working. When they do not match the new link scheme, you want to redirect with 301 (or 302) to correct page in the new URL scheme. All these can be managed via backend module.</p>
<p>My first thought was I need a filter to catch sfError404Exception and handle redirections from there. Well, in Symfony 1.4 you can&#8217;t do it without changing the Symfony core files, so it&#8217;s not an option. This is because <strong>the filters are not even get called</strong>, as <strong>routing</strong> finds out first, that the module and/or action does not exists and throws this exception.</p>
<p><strong>The solution:</strong><br />
<span id="more-227"></span><br />
There is the easier way of doing this. First you need to add new route that catches all that does not match current link scheme. <strong>In fact you need to replace</strong> <em>default</em> and <em>default_index</em> routes with something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;"># apps/frontend/config/routing.yml
&nbsp;
your_other_routes_here: ~
&nbsp;
# generic rules
# please, remove them by adding more specific rules
# default_index:
#  url:   /:module
#  param: { action: index }
&nbsp;
# default:
#  url:   /:module/:action/*
&nbsp;
# at the very end of the file
catchall:
  url:   /*
  param: { module: default, action: catchall }</pre></div></div>

<p>If you still need <em>default</em> and <em>default_index</em> routes you need to somehow handle forwards in your executeCatchall action. Please note that the above <em>catchall</em> route cannot be combined together with <em>default</em> and <em>default_index</em>. If you put catchall above these two, they won&#8217;t be executed ever, on the other hand &#8211; if you put it below these two, <em>catchall</em> will never be executed.</p>
<p>Then in this case you need to create executeCatchall action in your default module:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// apps/frontend/modules/default/actions/actions.class.php</span>
<span style="color: #000000; font-weight: bold;">class</span> defaultActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeCatchall<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// find your redirectation using $request-&gt;getPathInfo()</span>
    <span style="color: #000088;">$redirection</span> <span style="color: #339933;">=</span> Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Redirection'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findOneByPathInfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPathInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// this ensures that if there is no specified redirection, the old sfError404Exception gets thrown</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">forward404Unless</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$redirection</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
    <span style="color: #666666; font-style: italic;">// redirect</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$redirection</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'redirect_to'</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></pre></div></div>

<p>In the above example I&#8217;m assuming the following model class:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">Redirection:
  columns:
    path_info:        { type: string(255) }
    redirect_to:      { type: string(255) }</pre></div></div>

<p>Of course this is very basic implementation of redirection functionality, but it shows the correct way of doing it. I hope it&#8217;ll help.</p>
<p><strong>What&#8217;s wrong with handling sfError404Exception inside the execute404() action?</strong></p>
<p>Well, it often happens that you need to throw sfError404Exception in your actions. It doesn&#8217;t feel right for me to throw this exception inside the method that handles it.</p>
]]></content:encoded>
			<wfw:commentRss>http://janusz.slota.name/blog/2011/12/how-to-handle-sferror404exception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to set default value or option in the Symfony embeded form inside the Action</title>
		<link>http://janusz.slota.name/blog/2011/09/how-to-set-default-value-or-option-in-the-symfony-embeded-form-inside-the-action/</link>
		<comments>http://janusz.slota.name/blog/2011/09/how-to-set-default-value-or-option-in-the-symfony-embeded-form-inside-the-action/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 13:23:56 +0000</pubDate>
		<dc:creator>Janusz Słota</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[embedded forms]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[symfony1]]></category>

		<guid isPermaLink="false">http://janusz.slota.name/blog/?p=210</guid>
		<description><![CDATA[Let&#8217;s say you have Symfony 1.4 form User with embedded form Entry class UserForm extends Something &#123; public function configure&#40;&#41; &#123; $this-&#62;embedForm&#40;'entry', new EntryForm&#40;&#41;&#41;; &#125; &#125; and let&#8217;s say that this embedded form contains sfWidgetFormChoice widget class EntryForm extends BaseEntryForm &#123; public function configure&#40;&#41; &#123; $this-&#62;widgetSchema&#91;'cars'&#93; = new sfWidgetFormChoice&#40;array&#40; 'choices' =&#62; array&#40;&#41;, 'expanded' =&#62; true [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you have Symfony 1.4 form User with embedded form Entry</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> UserForm <span style="color: #000000; font-weight: bold;">extends</span> Something
<span style="color: #009900;">&#123;</span>
  <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;">embedForm</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'entry'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">new</span> EntryForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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><span id="more-210"></span><br />
and let&#8217;s say that this embedded form contains sfWidgetFormChoice widget</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> EntryForm <span style="color: #000000; font-weight: bold;">extends</span> BaseEntryForm
<span style="color: #009900;">&#123;</span>
  <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;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cars'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'choices'</span> <span style="color: #339933;">=&gt;</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: #0000ff;">'expanded'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</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;">'cars'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'choices'</span> <span style="color: #339933;">=&gt;</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;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Mind that choices option is an empty array &#8211; I want to set this option in the action as it depends on data in the session.</p>
<p>I found that, the following code in the action layer doesn&#8217;t work:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> defaultActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeIndex<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</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;">form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UserForm<span style="color: #009900;">&#40;</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;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getEmbeddedForm</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'entry'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWidget</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cars'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'choices'</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;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cars'</span><span style="color: #009900;">&#41;</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>Not sure why, but it&#8217;d work if the cars widget is attached to the UserForm. Maybe it&#8217;s related to <a href="http://trac.symfony-project.org/ticket/6548">this bug</a>. Anyway, if try to set option choices, it sets correctly, but the view layer ignores it.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> defaultActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeIndex<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</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;">form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UserForm<span style="color: #009900;">&#40;</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;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getEmbeddedForm</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'entry'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWidget</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cars'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'choices'</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;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cars'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <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;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getEmbeddedForm</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'entry'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWidget</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cars'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'choices'</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;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cars'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'setting up options for embedded forms works correctly, but the view layer seems to ignore it.'</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>So, if you have trouble setting up the dynamic options for the embedded form, you can do this, which seems to work.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> defaultActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeIndex<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</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;">form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UserForm<span style="color: #009900;">&#40;</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;">form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'entry'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cars'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWidget</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'choices'</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;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cars'</span><span style="color: #009900;">&#41;</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>Same problem is with validatorSchema. I found that this seems to work:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> defaultActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeIndex<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</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;">form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UserForm<span style="color: #009900;">&#40;</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;">form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'entry'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cars'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWidget</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'choices'</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;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cars'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// validator part</span>
    <span style="color: #000088;">$validatorSchema</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidatorSchema</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'entry'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cars'</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;">'choices'</span><span style="color: #339933;">,</span><span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</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;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cars'</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>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I hope it&#8217;ll help.</p>
]]></content:encoded>
			<wfw:commentRss>http://janusz.slota.name/blog/2011/09/how-to-set-default-value-or-option-in-the-symfony-embeded-form-inside-the-action/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What&#8217;s the average length of an email address?</title>
		<link>http://janusz.slota.name/blog/2009/05/email-length/</link>
		<comments>http://janusz.slota.name/blog/2009/05/email-length/#comments</comments>
		<pubDate>Tue, 05 May 2009 16:52:18 +0000</pubDate>
		<dc:creator>Janusz Słota</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">http://janusz.slota.name/blog/?p=1</guid>
		<description><![CDATA[This question always comes up, when you have to design new table in database to store email addresses. Is VARCHAR(30) long enough? Or maybe you should use VARCHAR(255) or maybe TEXT as I&#8217;ve seen in some projects? My live database, which I&#8217;ve used for this test contains 92298 valid email addresses, verified with the Pear [...]]]></description>
			<content:encoded><![CDATA[<p>This question always comes up, when you have to design new table in database to store email addresses. Is <strong>VARCHAR(30)</strong> long enough? Or maybe you should use <strong>VARCHAR(255)</strong> or maybe <strong>TEXT</strong> as I&#8217;ve seen in some projects?</p>
<p>My live database, which I&#8217;ve used for this test contains <strong>92298</strong> valid email addresses, verified with the <a href="http://pear.php.net/package/Validate" target="_blank">Pear Validate</a> class with domain checking.<br />
<span id="more-1"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>Validate<span style="color: #339933;">::</span><span style="color: #004000;">email</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</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;">// add to database</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// return error</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>It means, if the email address is in this database &#8211; it is real and correct, otherwise the field is empty. So to make sure not to include empty fields, I&#8217;ve issued following query:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">LENGTH</span><span style="color: #66cc66;">&#40;</span>email<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">SIZE</span> <span style="color: #993333; font-weight: bold;">FROM</span> customer <span style="color: #993333; font-weight: bold;">WHERE</span> email <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%@%'</span> <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #993333; font-weight: bold;">SIZE</span> <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #993333; font-weight: bold;">SIZE</span>;</pre></div></div>

<p>This query returns set of values, which I&#8217;ve used to create this chart (with <a title="OpenOffice.org" href="http://openoffice.org" target="_blank">OpenOffice.org</a> Calc).</p>
<p style="text-align: center;"><img class="size-full wp-image-12 aligncenter" title="Average emial address length" src="http://janusz.slota.name/blog/wp-content/uploads/2009/05/email-length-stats_html_54813cd4.jpg" alt="email-length-stats_html_54813cd4" width="815" height="241" /></p>
<p>As you can see majority of email addresses are around 13 to 34 characters long. To store email addresses I&#8217;ve used <strong>VARCHAR (255)</strong> but as you can see <strong>VARCHAR(50)</strong> is enough.</p>
<p>The answer: <strong>VARCHAR(50)</strong> should do.</p>
]]></content:encoded>
			<wfw:commentRss>http://janusz.slota.name/blog/2009/05/email-length/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

