<?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>Symfony-IT &#187; tips</title>
	<atom:link href="http://www.symfony.it/categoria/documentazione/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.symfony.it</link>
	<description>Just another Symfony Framework weblog</description>
	<lastBuildDate>Mon, 30 Jan 2012 13:53:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<div id='fb-root'></div>
					<script type='text/javascript'>
						window.fbAsyncInit = function()
						{
							FB.init({appId: null, status: true, cookie: true, xfbml: true});
						};
						(function()
						{
							var e = document.createElement('script'); e.async = true;
							e.src = document.location.protocol + '//connect.facebook.net/it_IT/all.js';
							document.getElementById('fb-root').appendChild(e);
						}());
					</script>	
						<item>
		<title>Usare Symfony2 con subversion</title>
		<link>http://www.symfony.it/articoli/520/usare-symfony2-con-subversion/</link>
		<comments>http://www.symfony.it/articoli/520/usare-symfony2-con-subversion/#comments</comments>
		<pubDate>Mon, 03 Oct 2011 14:39:54 +0000</pubDate>
		<dc:creator>Massimiliano Arione</dc:creator>
				<category><![CDATA[symfony2]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://www.symfony.it/?p=520</guid>
		<description><![CDATA[Edit: questo post è stato superato dalla pubblicazione di questa guida. Viene lasciato sul blog per motivi storici, ma si consiglia di seguire quanto spiegato nella guida suddetta. Sappiamo che Symfony2 predilige l&#8217;utilizzo di git come sistema di versionamento. Tuttavia, potrebbero esserci tutta una serie di ragioni per cui un progetto abbia bisogno di subversion: [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Edit</strong>: questo post è stato superato dalla pubblicazione di <a href="http://docs.symfony.it/cookbook/workflow/new_project_svn.html" title="Come creare e memorizzare un progetto Symfony2 in Subversion">questa guida</a>. Viene lasciato sul blog per motivi storici, ma si <em>consiglia di seguire quanto spiegato nella guida suddetta</em>.</p>
<hr />
<p>Sappiamo che Symfony2 predilige l&#8217;utilizzo di git come sistema di versionamento. Tuttavia, potrebbero esserci tutta una serie di ragioni per cui un progetto abbia bisogno di subversion: la stessa documentazione ufficiale ne fa <a href="http://docs.symfony.it/cookbook/workflow/new_project_git.html">un accenno</a>, purtroppo senza addentrarsi nei dettagli.<br />
Ecco qui cosa fare per avere un progetto Symfony2 funzionante con svn. Diamo per scontato di trovarci un una cartella in cui è stato fatto un checkout di un repository e in cui la cartella <em>vendor</em> di Symfony2 non sia presente (per esempio, perché il repository contiene uno scheletro di progetto simile a quello della <a href="http://symfony.com/download">Standard Edition</a> senza venditori).<br />
La prima cosa da fare è aggiungere i vari bundle e le altre dipendenza in externals:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> vendor
<span style="color: #c20cb9; font-weight: bold;">svn</span> pe <span style="color: #c20cb9; font-weight: bold;">svn</span>:externals vendor</pre></div></div>

<p>Nella finestra dell&#8217;editor, inserire le seguenti righe:</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;">symfony              http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>symfony<span style="color: #000000;">/</span>symfony<span style="color: #000000;">.</span>git
twig                 http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>fabpot<span style="color: #000000;">/</span>Twig<span style="color: #000000;">.</span>git
monolog              http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>Seldaek<span style="color: #000000;">/</span>monolog<span style="color: #000000;">.</span>git
doctrine<span style="color: #000000;">-</span>common      http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>doctrine<span style="color: #000000;">/</span>common<span style="color: #000000;">.</span>git
doctrine<span style="color: #000000;">-</span>dbal        http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>doctrine<span style="color: #000000;">/</span>dbal<span style="color: #000000;">.</span>git
doctrine             http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>doctrine<span style="color: #000000;">/</span>doctrine2<span style="color: #000000;">.</span>git
swiftmailer          http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>swiftmailer<span style="color: #000000;">/</span>swiftmailer<span style="color: #000000;">.</span>git
assetic              http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>kriswallsmith<span style="color: #000000;">/</span>assetic<span style="color: #000000;">.</span>git
twig<span style="color: #000000;">-</span>extensions      http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>fabpot<span style="color: #000000;">/</span>Twig<span style="color: #000000;">-</span>extensions<span style="color: #000000;">.</span>git
metadata             http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>schmittjoh<span style="color: #000000;">/</span>metadata<span style="color: #000000;">.</span>git
&nbsp;
doctrine<span style="color: #000000;">-</span>extensions  http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>l3pp4rd<span style="color: #000000;">/</span>DoctrineExtensions<span style="color: #000000;">.</span>git
&nbsp;
bundles<span style="color: #000000;">/</span>Stof<span style="color: #000000;">/</span>DoctrineExtensionsBundle       http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>stof<span style="color: #000000;">/</span>StofDoctrineExtensionsBundle<span style="color: #000000;">.</span>git
&nbsp;
bundles<span style="color: #000000;">/</span>Sensio<span style="color: #000000;">/</span>Bundle<span style="color: #000000;">/</span>FrameworkExtraBundle  http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>sensio<span style="color: #000000;">/</span>SensioFrameworkExtraBundle<span style="color: #000000;">.</span>git
bundles<span style="color: #000000;">/</span>Sensio<span style="color: #000000;">/</span>Bundle<span style="color: #000000;">/</span>DistributionBundle    http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>sensio<span style="color: #000000;">/</span>SensioDistributionBundle<span style="color: #000000;">.</span>git
bundles<span style="color: #000000;">/</span>Sensio<span style="color: #000000;">/</span>Bundle<span style="color: #000000;">/</span>GeneratorBundle       http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>sensio<span style="color: #000000;">/</span>SensioGeneratorBundle<span style="color: #000000;">.</span>git
bundles<span style="color: #000000;">/</span>JMS<span style="color: #000000;">/</span>SecurityExtraBundle             http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>schmittjoh<span style="color: #000000;">/</span>JMSSecurityExtraBundle<span style="color: #000000;">.</span>git
&nbsp;
cg<span style="color: #000000;">-</span>library                                  http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>schmittjoh<span style="color: #000000;">/</span>cg<span style="color: #000000;">-</span>library<span style="color: #000000;">.</span>git
bundles<span style="color: #000000;">/</span>JMS<span style="color: #000000;">/</span>AopBundle                       http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>schmittjoh<span style="color: #000000;">/</span>JMSAopBundle<span style="color: #000000;">.</span>git
&nbsp;
symfony<span style="color: #000000;">/</span>src<span style="color: #000000;">/</span>Symfony<span style="color: #000000;">/</span>Bundle<span style="color: #000000;">/</span>AsseticBundle    http<span style="color: #000000;">://</span>svn<span style="color: #000000;">.</span>github<span style="color: #000000;">.</span><span style="color: #668080;">com</span><span style="color: #000000;">/</span>symfony<span style="color: #000000;">/</span>AsseticBundle<span style="color: #000000;">.</span>git</pre></div></div>

<p>Si noti che sono stati aggiunti, oltre ai bundle di base, alcuni altri bundle utili.<br />
Il problema di questo approccio è che github, almeno attualmente, non supporta il checkout di tag o branch tramite svn. Per questo le versioni dei vari venditori importate saranno quelle dei rispettivi <em>master</em>, quindi le versioni in sviluppo. Se quindi si riscontrano errori o eccezioni dovuti per esempio a metodi mancanti, si verifichi che il file <code>app/bootstrap.php.cache</code> contenga tutto ciò che è necessario. Ovviamente, va adattato anche il file relativo all&#8217;autoload:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// app/autoload.php</span>
<span style="color: #000088;">$loader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerNamespaces</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'Symfony'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>__DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/symfony/src'</span><span style="color: #339933;">,</span> __DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/bundles'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'Sensio'</span>           <span style="color: #339933;">=&gt;</span> __DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/bundles'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'JMS'</span>              <span style="color: #339933;">=&gt;</span> __DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/bundles'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'CG'</span>               <span style="color: #339933;">=&gt;</span> __DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/cg-library/src'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'Doctrine\\Common'</span> <span style="color: #339933;">=&gt;</span> __DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/doctrine-common/lib'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'Doctrine\\DBAL'</span>   <span style="color: #339933;">=&gt;</span> __DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/doctrine-dbal/lib'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'Doctrine'</span>         <span style="color: #339933;">=&gt;</span> __DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/doctrine/lib'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'Monolog'</span>          <span style="color: #339933;">=&gt;</span> __DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/monolog/src'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'Assetic'</span>          <span style="color: #339933;">=&gt;</span> __DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/assetic/src'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'Metadata'</span>         <span style="color: #339933;">=&gt;</span> __DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/metadata/src'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'Gedmo'</span>            <span style="color: #339933;">=&gt;</span> __DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/doctrine-extensions/lib'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'Stof'</span>             <span style="color: #339933;">=&gt;</span> __DIR__<span style="color: #339933;">.</span><span style="color: #0000ff;">'/../vendor/bundles'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>e anche quello relativo all&#8217;attivazione dei bundle:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// app/AppKernel.php</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> registerBundles<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$bundles</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #000000; font-weight: bold;">new</span> Symfony\Bundle\FrameworkBundle\FrameworkBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #000000; font-weight: bold;">new</span> Symfony\Bundle\SecurityBundle\SecurityBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #000000; font-weight: bold;">new</span> Symfony\Bundle\TwigBundle\TwigBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #000000; font-weight: bold;">new</span> Symfony\Bundle\MonologBundle\MonologBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #000000; font-weight: bold;">new</span> Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #000000; font-weight: bold;">new</span> Symfony\Bundle\DoctrineBundle\DoctrineBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #000000; font-weight: bold;">new</span> Symfony\Bundle\AsseticBundle\AsseticBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #000000; font-weight: bold;">new</span> Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #000000; font-weight: bold;">new</span> JMS\AopBundle\JMSAopBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #000000; font-weight: bold;">new</span> JMS\SecurityExtraBundle\JMSSecurityExtraBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #000000; font-weight: bold;">new</span> Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</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: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getEnvironment</span><span style="color: #009900;">&#40;</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: #0000ff;">'dev'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$bundles</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Symfony\Bundle\WebProfilerBundle\WebProfilerBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$bundles</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$bundles</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Aggiornamento: si può adattare facilmente <code>app/bootstrap.php.cache</code> con il comando</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">php .<span style="color: #000000; font-weight: bold;">/</span>vendor<span style="color: #000000; font-weight: bold;">/</span>bundles<span style="color: #000000; font-weight: bold;">/</span>Sensio<span style="color: #000000; font-weight: bold;">/</span>Bundle<span style="color: #000000; font-weight: bold;">/</span>DistributionBundle<span style="color: #000000; font-weight: bold;">/</span>Resources<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>build_bootstrap.php</pre></div></div>

<div class='wpfblike' style='height: 40px;'><fb:like href='http://www.symfony.it/articoli/520/usare-symfony2-con-subversion/' layout='default' show_faces='true' width='400' action='like' colorscheme='light' send='false' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.symfony.it/articoli/520/usare-symfony2-con-subversion/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Richiamare il &#8220;nonno&#8221; di una classe</title>
		<link>http://www.symfony.it/articoli/502/richiamare-il-nonno-di-una-classe/</link>
		<comments>http://www.symfony.it/articoli/502/richiamare-il-nonno-di-una-classe/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 12:44:27 +0000</pubDate>
		<dc:creator>Massimiliano Arione</dc:creator>
				<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.symfony.it/?p=502</guid>
		<description><![CDATA[Capita spesso in symfony, in cui l&#8217;ereditarietà è usata pesantemente, di dover sovrascrivere un metodo. A volte purtroppo questo metodo è a sua volta un override di un metodo della propria classe padre, come nel seguente esempio: 1 2 3 4 5 6 // funzione originale public function pippo&#40;&#41; &#123; parent:pippo&#40;&#41; // ecc. ecc. &#125; [...]]]></description>
			<content:encoded><![CDATA[<p>Capita spesso in symfony, in cui l&#8217;ereditarietà è usata pesantemente, di dover sovrascrivere un metodo.<br />
A volte purtroppo questo metodo è a sua volta un override di un metodo della propria classe padre, come nel seguente esempio:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// funzione originale</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> pippo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  parent<span style="color: #339933;">:</span>pippo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #666666; font-style: italic;">// ecc. ecc.</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Se siamo in un caso come questo e ci serve sovrascrivere la funzione <code>pippo()</code>, non possiamo ricorrere a <code>parent::</code>, perché richiamerebbe appunto la funzione che vogliamo aggirare. La soluzione è tanto semplice quanto efficace:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// nostra funzione di override</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> pippo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #990000;">call_user_func</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_parent_class</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_parent_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'pippo'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// ecc. ecc.</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In questo modo possiamo richiamare direttamente il <em>nonno</em> della nostra classe, invece del <em>padre</em> <img src='http://www.symfony.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class='wpfblike' style='height: 40px;'><fb:like href='http://www.symfony.it/articoli/502/richiamare-il-nonno-di-una-classe/' layout='default' show_faces='true' width='400' action='like' colorscheme='light' send='false' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.symfony.it/articoli/502/richiamare-il-nonno-di-una-classe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>task con progress bar</title>
		<link>http://www.symfony.it/articoli/376/task-con-progress-bar/</link>
		<comments>http://www.symfony.it/articoli/376/task-con-progress-bar/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 10:30:10 +0000</pubDate>
		<dc:creator>Massimiliano Arione</dc:creator>
				<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.symfony.it/?p=376</guid>
		<description><![CDATA[A volte può capitare di dover eseguire dei task che durano diversi minuti, per esempio per delle importazioni o per delle conversioni di grandi quantità di dati. In questi casi può essere molto utile avere nel terminale una barra di progressione, che indichi le quantità dei dati già lavorati e ancora da lavorare. Questa piccola [...]]]></description>
			<content:encoded><![CDATA[<p>A volte può capitare di dover eseguire dei task che durano diversi minuti, per esempio per delle importazioni o per delle conversioni di grandi quantità di dati. In questi casi può essere molto utile avere nel terminale una barra di progressione, che indichi le quantità dei dati già lavorati e ancora da lavorare.<br />
Questa piccola classe è stata scritta per sfruttare l&#8217;ottimo pacchetto <a href="http://pear.php.net/package/Console_ProgressBar">Console_ ProgressBar di PEAR</a> (non reinventare la ruota!)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * progressbar task
 *
 * PEAR's Console_ProgressBar is required.
 * If Console_ProgressBar is not installed, no bar is displayed and no error is given
 * @see http://pear.php.net/package/Console_ProgressBar
 *
 * Usage: extend this class instead of sfBaseTask in your task.
 *        in your execute() method, call $this-&gt;init() and then other methods
 *        where appropriate.
 *
 * @author  Massimiliano Arione
 */</span>
abstract <span style="color: #000000; font-weight: bold;">class</span> progressbarTask <span style="color: #000000; font-weight: bold;">extends</span> sfBaseTask
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">protected</span>
    <span style="color: #000088;">$bar</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$hasBar</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * initialize ProgressBar
   */</span>
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> init<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;">hasBar</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">'Console/ProgressBar.php'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * start bar
   * @param integer $count total number of items
   */</span>
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> start<span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</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;">hasBar</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;">bar</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Console_ProgressBar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'[%bar%] %percent% %elapsed%'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'=&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span> <span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * update the bar
   * @param integer $step
   */</span>
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #000088;">$step</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;">hasBar</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;">bar</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$step</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * erase the bar
   */</span>
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> erase<span style="color: #009900;">&#40;</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;">hasBar</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;">bar</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">erase</span><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;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</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></td></tr></table></div>

<p>L&#8217;utilizzo è molto semplice: basta richiamare il metodo init(), quindi ogni volta che serve barra di progressione richiamare start(), update() ed erase() rispettivamente prima, durante e dopo il ciclo. Al metodo update() va passato un contatore, che deve essere incrementato nel ciclo stesso.</p>
<div class='wpfblike' style='height: 40px;'><fb:like href='http://www.symfony.it/articoli/376/task-con-progress-bar/' layout='default' show_faces='true' width='400' action='like' colorscheme='light' send='false' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.symfony.it/articoli/376/task-con-progress-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic authentication</title>
		<link>http://www.symfony.it/articoli/316/basic-authentication/</link>
		<comments>http://www.symfony.it/articoli/316/basic-authentication/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 09:23:59 +0000</pubDate>
		<dc:creator>Massimiliano Arione</dc:creator>
				<category><![CDATA[tips]]></category>
		<category><![CDATA[varie]]></category>

		<guid isPermaLink="false">http://www.symfony.it/?p=316</guid>
		<description><![CDATA[Può capitare di avere un progetto in symfony che non prevede utenti, ma che ha comunque un&#8217;interfaccia di amministrazione. In questo caso, vale la pena installare sfGuardPlugin solo per far accedere un singolo utente? Ovviamente no. Vediamo allora come risolvere il problema in modo semplice ed elegante. Supponiamo di trovarci in una configurazione standard, con [...]]]></description>
			<content:encoded><![CDATA[<p>Può capitare di avere un progetto in symfony che non prevede utenti, ma che ha comunque un&#8217;interfaccia di amministrazione. In questo caso, vale la pena installare sfGuardPlugin solo per far accedere un singolo utente? Ovviamente no.<br />
Vediamo allora come risolvere il problema in modo semplice ed elegante.<br />
Supponiamo di trovarci in una configurazione standard, con l&#8217;opzione security attivata per l&#8217;applicazione backend, e di avere a disposizione un modulo chiamato &#8220;default&#8221;. Se si preferisce un modulo diverso, occorre configurare opportunamente il file settings.yml per farvi puntare il login. Il primo passo consiste nell&#8217;aggiungere una rotta in routing.yml:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="yml" style="font-family:monospace;">login:
  url:   /login
  param: { module: default, action: login }</pre></td></tr></table></div>

<p>Inseriamo poi le credenziali dell&#8217;utente che deve accedere al backend, nel file app.yml dell&#8217;applicazione:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="yml" style="font-family:monospace;">all:
  admin_user:     admin
  # qui conviene mettere una password migliore :-)
  admin_password: admin</pre></td></tr></table></div>

<p>Basterà quindi inserire la sequente azione nel modulo default:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td 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> executeLogin<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: #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;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isAuthenticated</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: #b1b100;">return</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: #0000ff;">'@homepage'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</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;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_AUTH_USER'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_AUTH_USER'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'app_admin_user'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span>
        <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_AUTH_PW'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'app_admin_password'</span><span style="color: #009900;">&#41;</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;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAuthenticated</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">return</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;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUri</span><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>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setStatusCode</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">401</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;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setHttpHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WWW_Authenticate'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Basic realm=&quot;Authentication required&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> sfView<span style="color: #339933;">::</span><span style="color: #004000;">NONE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>E il gioco è fatto. Eventualmente si può personalizzare il messaggio &#8220;Authentication required&#8221;.<br />
Nei test funzionali, sarà possibile effettuare il login usando il metodo setAuth(), con l&#8217;accortezza di seguire il redirect dopo il primo get.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">setAuth</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">with</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'response'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isRedirected</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">followRedirect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
 <span style="color: #666666; font-style: italic;">// eccetera...</span></pre></td></tr></table></div>

<div class='wpfblike' style='height: 40px;'><fb:like href='http://www.symfony.it/articoli/316/basic-authentication/' layout='default' show_faces='true' width='400' action='like' colorscheme='light' send='false' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.symfony.it/articoli/316/basic-authentication/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Testare più email contemporaneamente</title>
		<link>http://www.symfony.it/articoli/260/testare-piu-email-contemporaneamente/</link>
		<comments>http://www.symfony.it/articoli/260/testare-piu-email-contemporaneamente/#comments</comments>
		<pubDate>Fri, 28 May 2010 09:38:54 +0000</pubDate>
		<dc:creator>fullo</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[sfTestMailer]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.symfony.it/?p=260</guid>
		<description><![CDATA[Può capitare di inviare dalla stessa action diverse email, ad esempio per notificare un amministratore di un determinato evento e contemporaneamente per dare feedback all&#8217;utente che l&#8217;ha scatenato. In questi casi sfTesterMailer, che con il metodo withMessage(), ci viene incontro dandoci la possibilità di filtrare, filtrando per destinatario, l&#8217;email che vogliamo testare. Supponiamo ad esempio [...]]]></description>
			<content:encoded><![CDATA[<p>Può capitare di inviare dalla stessa <code>action</code> diverse email, ad esempio per notificare un amministratore di un determinato evento e contemporaneamente per dare feedback all&#8217;utente che l&#8217;ha scatenato.</p>
<p>In questi casi <code>sfTesterMailer</code>, che con il metodo <code>withMessage()</code>, ci viene incontro dandoci la possibilità di filtrare, filtrando per destinatario, l&#8217;email che vogliamo testare.</p>
<p>Supponiamo ad esempio di aver spedito due email, una a admin@example.org e l&#8217;altra ad user@example.org in questo ordine. </p>
<p>Il test funzionale corrispondente sarà:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">with<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mailer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">hasSent</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">checkHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'to'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/admin@example.org/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">withMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user@example.org'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">checkHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'to'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/user@example.org/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
<span style="color: #990000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Inoltre il metodo <code>withMessage()</code> ci permette anche di ciclare all&#8217;interno dei messaggi, usando un secondo parametro denominato <code>$position</code>, casomai i messaggi inviati all&#8217;utente siano più di uno.</p>
<div class='wpfblike' style='height: 40px;'><fb:like href='http://www.symfony.it/articoli/260/testare-piu-email-contemporaneamente/' layout='default' show_faces='true' width='400' action='like' colorscheme='light' send='false' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.symfony.it/articoli/260/testare-piu-email-contemporaneamente/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deselezionare le opzioni di una select multipla in un test funzionale</title>
		<link>http://www.symfony.it/articoli/162/deselezionare-le-opzioni-di-una-select-multipla-in-un-test-funzionale/</link>
		<comments>http://www.symfony.it/articoli/162/deselezionare-le-opzioni-di-una-select-multipla-in-un-test-funzionale/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 11:06:50 +0000</pubDate>
		<dc:creator>filippo</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[function testing]]></category>
		<category><![CDATA[sfTestBrowser]]></category>
		<category><![CDATA[symfony1.2]]></category>

		<guid isPermaLink="false">http://www.symfony.it/?p=162</guid>
		<description><![CDATA[Mi è capitato questa mattina di dover fare un test funzionale in cui avevo bisogno di deselezionare una serie di opzioni da una select (all&#8217;interno di una form) lasciandone però alcuni selezionati. Guardando sulla documentazione dell&#8217;sfTestBrowser ho trovato un metodo per il select e deselect di radiobutton o checkbox. Sfortunatamente non ho trovato un metodo [...]]]></description>
			<content:encoded><![CDATA[<p>Mi è capitato questa mattina di dover fare un test funzionale in cui avevo bisogno di deselezionare una serie di opzioni da una select (all&#8217;interno di una form) lasciandone però alcuni selezionati. Guardando sulla documentazione dell&#8217;sfTestBrowser ho trovato un metodo per il <a href="http://www.symfony-project.org/api/1_2/sfTestFunctionalBase#method_select">select e deselect di radiobutton o checkbox</a>. Sfortunatamente non ho trovato un metodo per deselezionare le opzioni di una select senza dover <a href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/11">passare un array in post</a>.</p>
<p>Con il mio &#8220;pair&#8221; mattutino abbiamo quindi deciso di creare un nuovo metodo che sfruttasse il DOM di una pagina html e che potesse rimuovere la selezione di una opzione dato il nome o l&#8217;id della select e il valore dell&#8217;option.</p>
<p>Abbiamo aperto anche un <a href="http://trac.symfony-project.org/ticket/6686">ticket sul track di Symfony</a> dove potete trovare il <a href="http://trac.symfony-project.org/attachment/ticket/6686/idDoctrineTestBrowser.class.2.php">nuovo metodo</a> e il <a href="http://trac.symfony-project.org/attachment/ticket/6686/idDoctrineTestBrowserTest.php">test unitario</a> che ne verifica la correttezza!</p>
<p>Buon testing a tutti!!</p>
<div class='wpfblike' style='height: 40px;'><fb:like href='http://www.symfony.it/articoli/162/deselezionare-le-opzioni-di-una-select-multipla-in-un-test-funzionale/' layout='default' show_faces='true' width='400' action='like' colorscheme='light' send='false' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.symfony.it/articoli/162/deselezionare-le-opzioni-di-una-select-multipla-in-un-test-funzionale/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>group by</title>
		<link>http://www.symfony.it/articoli/121/group-by/</link>
		<comments>http://www.symfony.it/articoli/121/group-by/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 14:17:14 +0000</pubDate>
		<dc:creator>Massimiliano Arione</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[symfony1.2]]></category>

		<guid isPermaLink="false">http://www.symfony.it/?p=121</guid>
		<description><![CDATA[Quante volte vi è capitato di dover fare una semplice group by per contare le righe di una tabella raggruppate per una data colonna? Per intenderci, quello che si fa in maniera semplicissima in SQL con SELECT TYPE,COUNT&#40;*&#41; AS num FROM card GROUP BY TYPE; Purtroppo con Propel la cosa non appare subito immediata. Ecco [...]]]></description>
			<content:encoded><![CDATA[<p>Quante volte vi è capitato di dover fare una semplice <em>group by</em> per contare le righe di una tabella raggruppate per una data colonna? Per intenderci, quello che si fa in maniera semplicissima in SQL con</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;">TYPE</span><span style="color: #66cc66;">,</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: #993333; font-weight: bold;">AS</span> num <span style="color: #993333; font-weight: bold;">FROM</span> card <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;">TYPE</span>;</pre></div></div>

<p>Purtroppo con Propel la cosa non appare subito immediata. Ecco quindi un prezioso metodo da aggiungere alla vostra classe Peer per poterlo fare in modo semplice. Prima di tutto occorre inserire una nuova proprietà $count nel vostro modello (che nel mio esempio si chiama &#8220;Card&#8221;), con relativi <em>getter</em> e <em>setter</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$count</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setCount<span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</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;">count</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$count</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ecco quindi il pezzo forte, in CardPeer (ricordate sempre che va adattato secondo il nome del vostro modello):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * grouped select
 * @param  Criteria $c
 * @param  string   $column
 * @return array
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> doSelectGroupBy<span style="color: #009900;">&#40;</span>Criteria <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$column</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: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Criteria<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">addSelectColumns</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addGroupByColumn</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$column</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAsColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cnt'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'COUNT(*)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$stmt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">doSelectStmt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$cards</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: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span>PDO<span style="color: #339933;">::</span><span style="color: #004000;">FETCH_NUM</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$card</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Card<span style="color: #339933;">;</span>
    <span style="color: #000088;">$col</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$card</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hydrate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$card</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$col</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$col</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$cards</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$card</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$cards</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ecco infine un esempio di utilizzo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$cards</span> <span style="color: #339933;">=</span> CardPeer<span style="color: #339933;">::</span><span style="color: #004000;">doSelectGroupBy</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> CardPeer<span style="color: #339933;">::</span><span style="color: #004000;">TYPE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<div class='wpfblike' style='height: 40px;'><fb:like href='http://www.symfony.it/articoli/121/group-by/' layout='default' show_faces='true' width='400' action='like' colorscheme='light' send='false' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.symfony.it/articoli/121/group-by/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>personalizzare i filtri nel backend</title>
		<link>http://www.symfony.it/articoli/101/personalizzare-i-filtri-nel-backend/</link>
		<comments>http://www.symfony.it/articoli/101/personalizzare-i-filtri-nel-backend/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 14:09:24 +0000</pubDate>
		<dc:creator>Massimiliano Arione</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[varie]]></category>

		<guid isPermaLink="false">http://www.symfony.it/?p=101</guid>
		<description><![CDATA[La generazione automatica dei moduli di backend è bellissima, ma a volte c&#8217;è da sistemare qualche dettaglio a mano. Un caso esemplare è la form dei filtri, che purtroppo resta in inglese anche se la localizzazione è stata abilitata. Ma con qualche riga aggiuntiva nella classe filter relativa, possiamo metterla facilmente in Italiano (o anche [...]]]></description>
			<content:encoded><![CDATA[<p>La generazione automatica dei moduli di backend è bellissima, ma a volte c&#8217;è da sistemare qualche dettaglio a mano. Un caso esemplare è la form dei filtri, che purtroppo resta in inglese anche se la localizzazione è stata abilitata. Ma con qualche riga aggiuntiva nella classe filter relativa, possiamo metterla facilmente in Italiano (o anche personalizzarla ulteriormente). Innanzitutto occorre individuare la classe giusta: se ad esempio il vostro modello si chiama &#8220;BlogPost&#8221;, dovete modificare il file lib/filter/BlogPostFilter.class.php. Aprite dunque il file, ed inserite queste righe all&#8217;interno del metodo configure():</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><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;">'created_at'</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;">'template'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'da %from_date%&lt;br /&gt; a %to_date%'</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;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'created_at'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'from_date'</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;">'format'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%day%/%month%/%year%'</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;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'created_at'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'from_date'</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;">'empty_values'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'year'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'anno'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'month'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mese'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'day'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'giorno'</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;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'created_at'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'to_date'</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;">'format'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%day%/%month%/%year%'</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;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'created_at'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'to_date'</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;">'empty_values'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'year'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'anno'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'month'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mese'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'day'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'giorno'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>come si può capire facilmente dal codice, non solo abbiamo messo le etichette in Italiano, ma abbiamo anche invertito l&#8217;ordine di mese e anno, portandolo nella forma che ci è più consona.<br />
Ovviamente le opzioni viste sopra si possono applicare anche ad un eventuale campo &#8220;updated_at&#8221;, o a qualsiasi altro campo di tipo data.</p>
<div class='wpfblike' style='height: 40px;'><fb:like href='http://www.symfony.it/articoli/101/personalizzare-i-filtri-nel-backend/' layout='default' show_faces='true' width='400' action='like' colorscheme='light' send='false' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.symfony.it/articoli/101/personalizzare-i-filtri-nel-backend/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sostituire l&#8217;helper &#8220;input_date_tag()&#8221; in Symfony 1.1</title>
		<link>http://www.symfony.it/articoli/40/sostituire-lhelper-input_date_tag-in-symfony-11/</link>
		<comments>http://www.symfony.it/articoli/40/sostituire-lhelper-input_date_tag-in-symfony-11/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 17:03:17 +0000</pubDate>
		<dc:creator>fullo</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[symfony1.1]]></category>

		<guid isPermaLink="false">http://www.symfony.it/?p=40</guid>
		<description><![CDATA[Come molti di voi avranno appreso, a partire da symfony 1.1 gli helper javascript (e relativi ai form) sono (imho giustamente) da considerarsi deprecati. Questo perché rendono la scrittura (ma anche l&#8217;utilizzo) del codice più complesso del dovuto stravolgendo (e forzando) logiche non sempre corrette. Tale scelta ha però portato ad alcune mancanze, prima tra [...]]]></description>
			<content:encoded><![CDATA[<p>Come molti di voi avranno appreso, a partire da <a href="http://www.symfony.it/articoli/25/symfony-11-e-il-validation-framework/">symfony 1.1</a> gli helper javascript (e relativi ai form) sono (imho giustamente) da considerarsi deprecati. Questo perché rendono la scrittura (ma anche l&#8217;utilizzo) del codice più complesso del dovuto stravolgendo (e forzando) logiche non sempre corrette.</p>
<p>Tale scelta ha però portato ad alcune mancanze, prima tra tutte l&#8217;impossibilità di definire un behavior <em>rich</em> per quelle form più spesso usate, una per tutte quella delle date.</p>
<p>Un&#8217;utile soluzione è quindi quella di includere all&#8217;interno della propria applicazione <a href="http://ui.jquery.com/">UI JQuery</a> e nello special modo il modulo <a href="http://ui.jquery.com/functional_demos/#ui.datepicker">datepicker</a>.</p>
<p><span id="more-40"></span></p>
<p>Supponiamo che all&#8217;interno della classe che definisce la form del nostro modello esista un widget definito come <code>sfWidgetFormDateTime()</code>. Per sostituire alla scomoda select multipla un calendario javascript dovremmo così agire:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> EventForm <span style="color: #000000; font-weight: bold;">extends</span> BaseEventForm
<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;">'date'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<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;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'date'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorDateTime<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'with_time'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</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></td></tr></table></div>

<p>definiamo quindi la vista che mostrerà la nostra form (supponendo di includere nel layout della nostra applicazione <code>jquery.js</code> e <code>ui.js</code>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;style type=&quot;text/css&quot;&gt;.embed + img { position: relative; left: -21px; top: -1px; }&lt;/style&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(&quot;#event_date&quot;).datepicker({ 
    showOn: &quot;button&quot;, 
    buttonImage: &quot;/web/images/calendar.gif&quot;, 
    buttonImageOnly: true 
}).addClass(&quot;embed&quot;);
&lt;/script&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>et voilà: un bellissimo calendario javascript tornerà a rendere &#8220;felici&#8221; le nostre applicazioni web 2.0 <img src='http://www.symfony.it/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div class='wpfblike' style='height: 40px;'><fb:like href='http://www.symfony.it/articoli/40/sostituire-lhelper-input_date_tag-in-symfony-11/' layout='default' show_faces='true' width='400' action='like' colorscheme='light' send='false' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.symfony.it/articoli/40/sostituire-lhelper-input_date_tag-in-symfony-11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Editare HTML in una textarea</title>
		<link>http://www.symfony.it/articoli/31/editare-html-in-una-textarea/</link>
		<comments>http://www.symfony.it/articoli/31/editare-html-in-una-textarea/#comments</comments>
		<pubDate>Tue, 20 May 2008 14:12:28 +0000</pubDate>
		<dc:creator>Massimiliano Arione</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.symfony.it/?p=31</guid>
		<description><![CDATA[Spesso può servire, specialmente se si sta scrivendo un CMS, utilizzare una textarea per l&#8217;editing del codice HTML. Purtroppo symfony, a ogni submit di un form, converte il contenuto della textarea stessa trasformando le entità HTML nei rispettivi simboli (c&#8217;è anche un ticket aperto a riguardo). Questo fastidioso comportamento fa sì che le pagine HTML [...]]]></description>
			<content:encoded><![CDATA[<p>Spesso può servire, specialmente se si sta scrivendo un CMS, utilizzare una textarea per l&#8217;editing del codice HTML. Purtroppo symfony, a ogni submit di un form, converte il contenuto della textarea stessa trasformando le entità HTML nei rispettivi simboli (c&#8217;è anche un <a title="fix_double_escape is sometimes undesiderated" href="http://trac.symfony-project.com/ticket/3503">ticket aperto a riguardo</a>). Questo fastidioso comportamento fa sì che le pagine HTML create in tal modo non siano più validate, perché tutti i vostri &#8220;&amp;amp;&#8221; diventeranno inesorabilmente &#8220;&amp;&#8221;.</p>
<p>Per ovviare a questo inconveniente, nell&#8217;attesa che il ticket sia chiuso, si può usare questo escamotage. Creare una classe, per esempio /lib/fixAmp.class.php</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> fixAmp
<span style="color: #009900;">&#123;</span>
  <span style="color: #009933; font-style: italic;">/**
   * fix ampersands in HTML strings
   * @param  string $txt
   * @return string
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> fixAmps<span style="color: #009900;">&#40;</span><span style="color: #000088;">$txt</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$txt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_eregi_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;amp;(?!amp;)'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;amp;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$txt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$txt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_eregi_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;amp;#(\d+);'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;#\1;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$txt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// for numeric entities</span>
    <span style="color: #000088;">$txt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_eregi_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;amp;(\w+);'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;\1;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$txt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// for literal entities</span>
    <span style="color: #000088;">$txt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_eregi_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;amp;&amp;amp;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;&amp;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$txt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// for php boolean control</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$txt</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Quindi nella action basterà applicare il metodo al testo ottenuto dalla textarea.<br />
Ad esempio</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$myClass</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setContent</span><span style="color: #009900;">&#40;</span>fixAmps<span style="color: #339933;">::</span><span style="color: #004000;">fixAmps</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;">'content'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>La classe vista sopra utilizza mb_eregi_replace() per poter funzionare con i caratteri multi-byte, ma si può facilmente modificare per l&#8217;utilizzo con preg_replace()</p>
<div class='wpfblike' style='height: 40px;'><fb:like href='http://www.symfony.it/articoli/31/editare-html-in-una-textarea/' layout='default' show_faces='true' width='400' action='like' colorscheme='light' send='false' /></div>]]></content:encoded>
			<wfw:commentRss>http://www.symfony.it/articoli/31/editare-html-in-una-textarea/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
