<?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>Il Blog di Daniela Remogna alias ~FiMiEtTa~</title>
	<atom:link href="http://www.fimietta.it/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fimietta.it/blog</link>
	<description></description>
	<lastBuildDate>Mon, 28 Jan 2013 21:00:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Come creare una UILabel da codice senza utilizzare Interface Builder in Objective-c</title>
		<link>http://www.fimietta.it/blog/come-creare-una-uilabel-da-codice-senza-utilizzare-interface-builder-in-objective-c.html</link>
		<comments>http://www.fimietta.it/blog/come-creare-una-uilabel-da-codice-senza-utilizzare-interface-builder-in-objective-c.html#comments</comments>
		<pubDate>Fri, 23 Mar 2012 20:04:37 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Objective C]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2844</guid>
		<description><![CDATA[Una UILabel è utilizzata in genere per visualizzare una riga di testo:
UILabel *myLabel = &#91;&#91;UILabel alloc&#93; initWithFrame:CGRectMake&#40;50, 100, 200, 100&#41;&#93;;

myLabel.text = @&#34;Hello World!&#34;;

&#91;self.view addSubview:myLabel&#93;;
  
]]></description>
			<content:encoded><![CDATA[<p>Una UILabel è utilizzata in genere per visualizzare una riga di testo:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">UILabel <span style="color: #002200;">*</span>myLabel <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">50</span>, <span style="color: #2400d9;">100</span>, <span style="color: #2400d9;">200</span>, <span style="color: #2400d9;">100</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
<br />
myLabel.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Hello World!&quot;</span>;<br />
<br />
<span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span>myLabel<span style="color: #002200;">&#93;</span>;</div></div>
<p> <img src='http://www.fimietta.it/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/come-creare-una-uilabel-da-codice-senza-utilizzare-interface-builder-in-objective-c.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tool per testare il codice PHP online</title>
		<link>http://www.fimietta.it/blog/tool-per-testare-il-codice-php-online.html</link>
		<comments>http://www.fimietta.it/blog/tool-per-testare-il-codice-php-online.html#comments</comments>
		<pubDate>Wed, 21 Mar 2012 13:16:56 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2839</guid>
		<description><![CDATA[Segnalo questo tool online  che permette di scrivere del codice PHP e di testarlo online in modo semplice e veloce:
http://writecodeonline.com/php/

Ad esempio se volete vedere l&#8217;output generato dal seguente codice:
echo date&#40;'Y-m-d', strtotime&#40; '+3 day' &#41;&#41;;
Che non fa altro che mostrare sul browser la data di oggi aumentata di tre giorni, potete farlo usando il servizio [...]]]></description>
			<content:encoded><![CDATA[<p>Segnalo questo <strong>tool online</strong>  che permette di scrivere del codice PHP e di testarlo online in modo semplice e veloce:</p>
<p><a href="http://writecodeonline.com/php/" target="_blank">http://writecodeonline.com/php/</a><br />
</p>
<p>Ad esempio se volete vedere l&#8217;output generato dal seguente codice:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">echo</span> <a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/strtotime"><span style="color: #990000;">strtotime</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'+3 day'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Che non fa altro che mostrare sul browser la data di oggi aumentata di tre giorni, potete farlo usando il servizio di <strong>WriteCodeOnline</strong>:</p>
<div id="attachment_2840" class="wp-caption alignleft" style="width: 600px"><a href="http://www.fimietta.it/blog/wp-content/uploads/2012/03/write_code_online_php.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/03/write_code_online_php.png" alt="write_code_online_php" title="write_code_online_php" width="590" height="367" class="size-full wp-image-2840" /></a><p class="wp-caption-text">write_code_online_php</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/tool-per-testare-il-codice-php-online.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LMS &#8211; An Elearning Platform with Online activation and 5 free users forever</title>
		<link>http://www.fimietta.it/blog/lms-an-elearning-platform-with-online-activation-and-5-free-users-forever.html</link>
		<comments>http://www.fimietta.it/blog/lms-an-elearning-platform-with-online-activation-and-5-free-users-forever.html#comments</comments>
		<pubDate>Tue, 07 Feb 2012 18:23:15 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[E-learning]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2833</guid>
		<description><![CDATA[Docebo Cloud E-Learning

Use Docebo to train your staff!
Online activation and 5 free users forever
Courses already installed
Upload your materials, create tests and reports
Cloud Ready, Mobile features


]]></description>
			<content:encoded><![CDATA[<h3>Docebo Cloud E-Learning</h3>
<ol>
<li>Use Docebo to train your staff!</li>
<li>Online activation and 5 free users forever</li>
<li>Courses already installed</li>
<li>Upload your materials, create tests and reports</li>
<li>Cloud Ready, Mobile features</li>
</ol>
<p><a href="http://www.docebo.com/cms/home_elearning_lms_multimeda_courses"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/02/lms-platform-free.png" alt="" title="lms-platform-free-elearning" width="550" height="203" class="alignleft size-full wp-image-2834" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/lms-an-elearning-platform-with-online-activation-and-5-free-users-forever.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LMS &#8211; Piattaforma di E-learning gratis per i primi 5 utenti&#8230;.</title>
		<link>http://www.fimietta.it/blog/piattaforma-di-e-learning-gratis-per-i-primi-5-utenti.html</link>
		<comments>http://www.fimietta.it/blog/piattaforma-di-e-learning-gratis-per-i-primi-5-utenti.html#comments</comments>
		<pubDate>Tue, 07 Feb 2012 18:18:21 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[E-learning]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2828</guid>
		<description><![CDATA[
Usa Docebo per il training del tuo staff!
Attivazione online e 5 utenti gratuiti!
Corsi già installati
Carica i tuoi contenuti, crea test e report
Cloud Ready, funzionalità Mobile


]]></description>
			<content:encoded><![CDATA[<ul>
<li>Usa <strong>Docebo</strong> per il <strong>training del tuo staff</strong>!</li>
<li>Attivazione online e 5 utenti gratuiti!</li>
<li>Corsi già installati</li>
<li>Carica i tuoi contenuti, crea test e report</li>
<li>Cloud Ready, funzionalità Mobile</li>
</ul>
<p><a href="http://www.docebo.com"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/02/piattaforma-di-elearning-gratis1.png" alt="" title="piattaforma-di-elearning-gratis" width="550" height="196" class="alignleft size-full wp-image-2830" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/piattaforma-di-e-learning-gratis-per-i-primi-5-utenti.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gli Active Record di Yii: un design pattern per rappresentare le tabelle del database in un modo orientato agli oggetti.</title>
		<link>http://www.fimietta.it/blog/gli-active-record-di-yii-un-design-pattern-per-rappresentare-le-tabelle-del-database-in-un-modo-orientato-agli-oggetti.html</link>
		<comments>http://www.fimietta.it/blog/gli-active-record-di-yii-un-design-pattern-per-rappresentare-le-tabelle-del-database-in-un-modo-orientato-agli-oggetti.html#comments</comments>
		<pubDate>Wed, 01 Feb 2012 09:16:01 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2766</guid>
		<description><![CDATA[Gli Active Record sono un design pattern per interagire con il database in un modo semplice: l&#8217;obiettivo è di evitare di scrivere delle noiosissime query SQL per le comuni operazioni CRUD (create, read, update and delete).
Gli Active Record (AR), in altri termini, sono l&#8217;implementazione delle tecnica di programmazione basata sull&#8217;Object-Relational Maping (ORM)(http://it.wikipedia.org/wiki/Object-relational_mapping).

Gli Active Record trasformano:

 [...]]]></description>
			<content:encoded><![CDATA[<p>Gli <strong>Active Record</strong> sono un design pattern <em>per interagire con il database in un modo semplice</em>: l&#8217;obiettivo è di evitare di scrivere delle noiosissime query SQL per le comuni operazioni CRUD (create, read, update and delete).</p>
<p>Gli <strong>Active Record (AR)</strong>, in altri termini, sono l&#8217;implementazione delle tecnica di programmazione basata sull&#8217;<strong>Object-Relational Maping</strong> (ORM)(<a href="http://it.wikipedia.org/wiki/Object-relational_mapping" target="_blank">http://it.wikipedia.org/wiki/Object-relational_mapping</a>).</p>
<div id="attachment_2814" class="wp-caption alignleft" style="width: 600px"><a href="http://www.fimietta.it/blog/wp-content/uploads/2012/02/database-orm.jpg"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/02/database-orm.jpg" alt="database-orm" title="database-orm" width="590" height="245" class="size-full wp-image-2814" /></a><p class="wp-caption-text">database-orm</p></div>
<p><span id="more-2766"></span></p>
<p>Gli <strong>Active Record</strong> trasformano:</p>
<ul>
<li> le tabelle in classi</li>
<li>le righe in oggetti ed i campi in attributi</li>
</ul>
<p>Secondo quest&#8217;ottica, le comuni operazioni CRUD sono implementate tramite <strong>dei metodi degli Active Record</strong>.</p>
<h3>Inserimento di un nuovo record</h3>
<p>Ad esempio per inserire un nuovo <strong>post</strong> nella tabella <strong>tbl_post</strong>:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> Post<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'sample post'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'post body content'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Come potete notare non è necessario scrivere la query &#8220;<strong>INSERT INTO tbl_post(&#8230;&#8230;) VALUES(&#8230;..)</strong>&#8220;, ma semplicemente si crea un oggetto <strong>$post</strong> che è un&#8217;istanza della classe Post, si impostano i valori dei campi della tabella come se fossero delle proprietà di una classe ($post->title per impostare il titolo) ed infine si inserisce il record invocando il metodo <strong>save()</strong> ( $post->save() ).</p>
<h3>Come creare gli Active Record collegati ad una tabella del database</h3>
<p>Ora supponiamo di avere una tabella con la seguente struttura:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> tbl_post <span style="color: #66cc66;">&#40;</span><br />
&nbsp; &nbsp; id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> AUTOINCREMENT<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; title <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">128</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; content TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; create_time <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><br />
<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Per accedere ad una tabella del database secondo la logica ORM, bisogna prima definire <strong>una classe AR</strong> che estende la classe<strong> CActiveRecord</strong>.<br />
Ricordo che <strong>ciascuna classe AR</strong> rappresenta una <strong>tabella </strong>mentre <strong>un istanza</strong> della classe AR rappresenta <strong>una riga della tabella</strong>.</p>
<p>Ecco il codice minimale per implementare la classe AR per la tabella tbl_post:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> Post <span style="color: #000000; font-weight: bold;">extends</span> CActiveRecord<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> model<span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> tableName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'tbl_post'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Attenzione che per default,<strong> il nome della classe AR è la stessa del nome della tabella</strong>.<br />
Se invece sono diverse è necessario fare <strong>un ovverride</strong> del metodo <strong>tableName()</strong>.</p>
<p>I <strong>valori delle colonne di una tabella</strong> possono essere accedute<strong> come proprietà </strong>della<strong> corrispondente istanza AR</strong>.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> Post<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'a sample post'</span><span style="color: #339933;">;</span></div></div>
<p>E&#8217; importante notare che anche se la proprietà &#8220;<strong>title</strong>&#8221; non è stata esplicitamente dichiarata all&#8217;interno della classe <strong>Post</strong>, in realtà possiamo ugualmente accederci perché &#8220;<strong>title</strong>&#8221; è una<strong> colonna </strong>della tabella <strong>tbl_post</strong> e <strong>CActiveRecord</strong> permette che <strong>title </strong>sia accessibile come proprietà con l&#8217;aiutato del metodo magico <strong>__get() del PHP</strong>. In generale, nel caso in cui si tenti di accedere ad una colonna inesistente, il sistema solleva un&#8217;eccezione.</p>
<h3>Aggiungere un nuovo record nella tabella tbl_post</h3>
<p>Questi sono i semplici passi da seguire nel caso si voglia aggiungere un nuovo record in un tabella del database:</p>
<ol>
<li>Creare <strong>una nuova istanza della classe AR</strong> corrispondente alla tabella</li>
<li>Impostare le <strong>proprietà associate alle colonne</strong> della tabella</li>
<li>Richiamare il metodo<strong> save() </strong>per completare l&#8217;inserimento</li>
</ol>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> Post<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'sample post'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'content for the sample post'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create_time</span><span style="color: #339933;">=</span><a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Si può assegnare ad un attributo un valore di tipo <strong>CDbExpression</strong> prima che il record sia salvato nel database. </p>
<p>Ad esempio per salvare &#8220;<strong>un timestamp</strong>&#8221;  ritornato dalla funzione MySQL NOW() basta scrivere il seguente codice:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> Post<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create_time</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> CDbExpression<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'NOW()'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// $post-&gt;create_time='NOW()'; will not work because</span><br />
<span style="color: #666666; font-style: italic;">// 'NOW()' will be treated as a string</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Leggere i record</h3>
<p>Per leggere <strong>i dati di una tabella</strong> possiamo utilizzare <strong>i metodi find</strong>:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// trova la prima riga che soddisfa la condizione specificata</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// trova la riga con la chiave primaria specificata</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByPk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$postID</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// trova la riga con gli attributi specificati</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// trova la prima riga utilizzando lo statement sql specificato</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findBySql</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Il <strong>metodo statico model()</strong> ritorna <strong>un&#8217;istanza della classe AR</strong>  ed è <strong>obbligatorio </strong>per ciascuna classe AR.</p>
<p>Possiamo poi leggere i valori come se si accedesse ad un normale oggetto, ad esempio echo <strong>$post->title;</strong></p>
<p>Quando richiamiamo il metodo <strong>find</strong>, utilizziamo <strong>$condition</strong> e <strong>$params </strong>per specificare le <strong>condizioni della query</strong>. </p>
<p>La <strong>condizione</strong> può essere una stringa che rappresenta <strong>la clausola WHERE di uno statement SQL</strong> mentre <strong>$params</strong> è un array di parametri i cui valori possono essere <em>abbinati ai segnaposti</em> impostati nella <strong>$condition</strong>: </p>
<p>Per esempio:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// cerca la riga con postID=10</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'postID=:postID'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':postID'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>E&#8217; possibile specificare delle query più complesse utilizzando in realtà come <strong>$condition</strong> un&#8217;istanza della classe <strong>CDbCriteria</strong>.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$criteria</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> CDbCriteria<span style="color: #339933;">;</span><br />
<span style="color: #000088;">$criteria</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// only select the 'title' column</span><br />
<span style="color: #000088;">$criteria</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">condition</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'postID=:postID'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$criteria</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">params</span><span style="color: #339933;">=</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':postID'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$criteria</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// $params is not needed</span></div></div>
<p>Un metodo alternativo a <strong>CDbCriteria</strong> è di<em> passare un array </em>al metodo <strong>find</strong>.<br />
Come mostrato qui di seguito:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'select'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'condition'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'postID=:postID'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'params'</span><span style="color: #339933;">=&gt;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':postID'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Quando una <strong>query</strong> restituisce più di un record, possiamo usare il <strong>metodo findAll</strong>:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// find all rows satisfying the specified condition</span><br />
<span style="color: #000088;">$posts</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// find all rows with the specified primary keys</span><br />
<span style="color: #000088;">$posts</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAllByPk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$postIDs</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// find all rows with the specified attribute values</span><br />
<span style="color: #000088;">$posts</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAllByAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// find all rows using the specified SQL statement</span><br />
<span style="color: #000088;">$posts</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAllBySql</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Se la <strong>findAll</strong> non trova nessun record che soddisfa le condizioni specificate restituisce <strong>un array vuoto</strong>.</p>
<p>Inoltre sono forniti questi metodi:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// get the number of rows satisfying the specified condition</span><br />
<span style="color: #000088;">$n</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// get the number of rows using the specified SQL statement</span><br />
<span style="color: #000088;">$n</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">countBySql</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// check if there is at least a row satisfying the specified condition</span><br />
<span style="color: #000088;">$exists</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Aggiornamento di Record</h3>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByPk</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'new post title'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// save the change to database</span></div></div>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// update the rows matching the specified condition</span><br />
Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">updateAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// update the rows matching the specified condition and primary key(s)</span><br />
Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">updateByPk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pk</span><span style="color: #339933;">,</span><span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// update counter columns in the rows satisfying the specified conditions</span><br />
Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">updateCounters</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$counters</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Cancellare un Record</h3>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">=</span>Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findByPk</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// assuming there is a post whose ID is 10</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// delete the row from the database table</span></div></div>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// delete the rows matching the specified condition</span><br />
Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deleteAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// delete the rows matching the specified condition and primary key(s)</span><br />
Post<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deleteByPk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pk</span><span style="color: #339933;">,</span><span style="color: #000088;">$condition</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Validazione dei dati</h3>
<p>Spesso e volentieri capita che nel momento in cui desideriamo inserire o aggiornare un record del database, abbiamo bisogno di controllare se il valore della colonna è conforme a delle regole specifiche.</p>
<p><strong>AR</strong> assolve alla <strong>validazione dei dati automaticamente</strong> quando il <strong>metodo save() </strong>è invocato.<br />
La validazione è basata su regole specificate <strong>nel metodo rules() </strong>della <strong>classe AR</strong>.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// data is valid and is successfully inserted/updated</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">else</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// data is invalid. call getErrors() to retrieve error messages</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Quando i dati da inserire o aggiornare sono inoltrati dal<strong> metodo post</strong> di un form, possiamo assegnarli alle rispettive <strong>proprietà della classe AR</strong> in questo modo:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Infine se desideriamo aggiornare più proprietà contemporaneamente in un colpo solo:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// assume $_POST['Post'] is an array of column values indexed by column names</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Post'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<h3>Risorse</h3>
<p>La fonte di questo articolo è <a href="http://www.yiiframework.com/doc/guide/1.1/it/database.arr" target="_blank">http://www.yiiframework.com/doc/guide/1.1/it/database.arr</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/gli-active-record-di-yii-un-design-pattern-per-rappresentare-le-tabelle-del-database-in-un-modo-orientato-agli-oggetti.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Come creare un pulsante dinamicamente in Objective-c &#8211; Iphone SDK</title>
		<link>http://www.fimietta.it/blog/come-creare-un-pulsante-dinamicamente-in-objective-c-iphone-sdk.html</link>
		<comments>http://www.fimietta.it/blog/come-creare-un-pulsante-dinamicamente-in-objective-c-iphone-sdk.html#comments</comments>
		<pubDate>Tue, 24 Jan 2012 22:15:31 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Objective C]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2798</guid>
		<description><![CDATA[Questa porzione di codice scritta in linguaggio Objective-c, crea dinamicamente un pulsante  di larghezza 150 ed altezza 30 e lo posiziona alle coordinate (80.0, 170.0).
Il pulsante avrà come label &#8220;My Custom Button&#8221;&#8221;

Il pulsante dovrà essere in grado di rispondere agli eventi di pressione per far ciò utilizzeremo un metodo della classe  UIControl, classe [...]]]></description>
			<content:encoded><![CDATA[<p>Questa porzione di codice scritta in linguaggio Objective-c, crea dinamicamente <strong>un pulsante</strong>  di larghezza 150 ed altezza 30 e lo posiziona alle <strong>coordinate (80.0, 170.0)</strong>.<br />
Il pulsante avrà come label <strong>&#8220;My Custom Button&#8221;</strong>&#8221;</p>
<p><span id="more-2798"></span></p>
<p>Il pulsante dovrà essere in grado di rispondere agli eventi di pressione per far ciò utilizzeremo un metodo della classe  <strong>UIControl</strong>, classe da cui deriva anche <strong>UIButton</strong>.<br />
Il metodo è</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">addTarget<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>target action<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>selector<span style="color: #002200;">&#41;</span>anAction forControlEvents<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIControlEventsType<span style="color: #002200;">&#41;</span>type</div></div>
<p>L&#8217;evento che in genere ci interessa intercettare in un bottone è generalmente <strong>UIControlEventTouchUpInside</strong>.</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">UIButton <span style="color: #002200;">*</span>button <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;<br />
button.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">80.0</span>, <span style="color: #2400d9;">170</span>, <span style="color: #2400d9;">150.0</span>, <span style="color: #2400d9;">30.0</span><span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#91;</span>button setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;My Custom Button&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>button addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>myButtonHandler<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span>button<span style="color: #002200;">&#93;</span>;<br />
<br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>myButtonHandler<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;new button clicked!!!&quot;</span><span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#125;</span></div></div>
<p>Ecco il risultato finale:</p>
<div id="attachment_2803" class="wp-caption alignleft" style="width: 210px"><a href="http://www.fimietta.it/blog/wp-content/uploads/2012/01/creare-dinamicamente-un-pulsante-in-objectivec1.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/01/creare-dinamicamente-un-pulsante-in-objectivec1.png" alt="creare-dinamicamente-un-pulsante-in-objectivec" title="creare-dinamicamente-un-pulsante-in-objectivec" width="200" height="391" class="size-full wp-image-2803" /></a><p class="wp-caption-text">creare-dinamicamente-un-pulsante-in-objectivec</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/come-creare-un-pulsante-dinamicamente-in-objective-c-iphone-sdk.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Actionscript 3 versus Objective-C: vediamo le principali differenze a livello di sintassi del codice</title>
		<link>http://www.fimietta.it/blog/actionscript-3-versus-objective-c-vediamo-le-principali-differenze-a-livello-di-sintassi-del-codice.html</link>
		<comments>http://www.fimietta.it/blog/actionscript-3-versus-objective-c-vediamo-le-principali-differenze-a-livello-di-sintassi-del-codice.html#comments</comments>
		<pubDate>Mon, 23 Jan 2012 21:05:15 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Objective C]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2784</guid>
		<description><![CDATA[Richiamare un metodo in AS3 / inviare un messaggio ad un oggetto in Objective C 
mySound.setVolume&#40;&#41;;
&#91;mySound setVolume&#93;;

Memorizzare un valore ritornato da un metodo in AS3 / Objective C
volume = mySound.getVolume&#40;&#41;;
volume = &#91;mySound getVolume&#93;;
Passaggio di un parametro ad un metodo in AS3 / Objective C
mySound.setVolume&#40;value&#41;;
&#91;mySound setVolume:value&#93;;
Passaggio di più parametri ad un metodo in AS3 / Objective [...]]]></description>
			<content:encoded><![CDATA[<h3>Richiamare un metodo in AS3 / inviare un messaggio ad un oggetto in Objective C </h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mySound.<span style="color: #0066CC;">setVolume</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">&#91;</span>mySound setVolume<span style="color: #002200;">&#93;</span>;</div></div>
<p><span id="more-2784"></span></p>
<h3>Memorizzare un valore ritornato da un metodo in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">volume = mySound.<span style="color: #0066CC;">getVolume</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">volume <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>mySound getVolume<span style="color: #002200;">&#93;</span>;</div></div>
<h3>Passaggio di un parametro ad un metodo in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mySound.<span style="color: #0066CC;">setVolume</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">&#91;</span>mySound setVolume<span style="color: #002200;">:</span>value<span style="color: #002200;">&#93;</span>;</div></div>
<h3>Passaggio di più parametri ad un metodo in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mySound.<span style="color: #006600;">setLeftAndRightPan</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">left</span>, <span style="color: #0066CC;">right</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">&#91;</span>mySound setLeftAndRightPan<span style="color: #002200;">:</span>left, rightValue<span style="color: #002200;">:</span>right<span style="color: #002200;">&#93;</span></div></div>
<h3>Definizione di un metodo in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setLeftAndRightPan<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">left</span>:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">right</span>:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setLeftAndRightPan<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>left, right<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>rightValue</div></div>
<h3>Variabili in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;<br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span> name <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #a61390;">string</span><span style="color: #002200;">&#93;</span>;</div></div>
<h3>Inizializzare una stringa in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> someString:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;foo&quot;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span> someString <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;foo&quot;</span>;</div></div>
<h3>Concatenare due stringhe in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> firstString:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;foo&quot;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> secondString:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;bar&quot;</span>;<br />
firstString = firstString + secondString;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>firstString <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;foo&quot;</span>;<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>secondString <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bar&quot;</span>;<br />
firstString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>firstString stringByAppendingString<span style="color: #002200;">:</span>secondString<span style="color: #002200;">&#93;</span>;</div></div>
<h3>Variabile intera in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> counter:<span style="color: #0066CC;">int</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">NSInteger counter;</div></div>
<h3>Object Variable in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> vo:DataVO;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DataVO <span style="color: #002200;">*</span>vo;</div></div>
<h3>Gestione delle memoria per classi complesse in AS3 / Objective c</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> destroy<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>timer<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; timer.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>, onTick<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; timer.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; timer = <span style="color: #000000; font-weight: bold;">null</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>icon<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; icon.<span style="color: #006600;">bitmapData</span>.<span style="color: #006600;">dispose</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #002200;">&#91;</span>timer release<span style="color: #002200;">&#93;</span><br />
&nbsp; &nbsp;<span style="color: #002200;">&#91;</span>icon release<span style="color: #002200;">&#93;</span><br />
&nbsp; &nbsp;<span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span><br />
<span style="color: #002200;">&#125;</span></div></div>
<h3>Lavorare con i MovieClip</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">//Actionscript 3</span><br />
<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> i : <span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span> ; i <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">10</span> ; i ++ <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">var</span> rect : Rectangle = <span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Custom object</span><br />
&nbsp; &nbsp; &nbsp;rect.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">50</span><span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">%</span>4<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;rect.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">90</span><span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;addChild<span style="color: #66cc66;">&#40;</span>rect<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>numChildren<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//result: 10</span></div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; <span style="color: #2400d9;">10</span> ; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;Rectangle <span style="color: #002200;">*</span>rect <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Rectangle alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">40</span>,<span style="color: #2400d9;">80</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//Custom Object</span><br />
&nbsp; &nbsp; &nbsp;rect.transform <span style="color: #002200;">=</span> CGAffineTransformMakeTranslation<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">50</span><span style="color: #002200;">*</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/floor.html"><span style="color: #a61390;">floor</span></a><span style="color: #002200;">&#40;</span>i<span style="color: #002200;">%</span>4<span style="color: #002200;">&#41;</span>, <span style="color: #2400d9;">90</span><span style="color: #002200;">*</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/floor.html"><span style="color: #a61390;">floor</span></a><span style="color: #002200;">&#40;</span>i<span style="color: #002200;">/</span><span style="color: #2400d9;">4</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span>rect<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//See that your window variable is accessible</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#91;</span>rect release<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%i&quot;</span>,<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>window subviews<span style="color: #002200;">&#93;</span> count<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">//result: 10</span></div></div>
<h3>Array in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> arr:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">10</span>, <span style="color: #cc66cc;">20</span>, <span style="color: #cc66cc;">30</span>, <span style="color: #cc66cc;">40</span>, <span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#93;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> num:<span style="color: #0066CC;">int</span> = arr<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> <span style="color: #002200;">*</span>arr <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> arrayWithObjects<span style="color: #002200;">:</span><span style="color: #2400d9;">10</span>, <span style="color: #2400d9;">20</span>, <span style="color: #2400d9;">30</span>, <span style="color: #2400d9;">40</span>, <span style="color: #2400d9;">50</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
NSInteger num <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>arr objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>;</div></div>
<h3>Loop su Array in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #66cc66;">*</span> <span style="color: #b1b100;">in</span> arr<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// do something with obj</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/"><span style="color: #400080;">NSObject</span></a> <span style="color: #002200;">*</span>obj <span style="color: #a61390;">in</span> arr<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// do something with obj</span><br />
<span style="color: #002200;">&#125;</span></div></div>
<h3>Array Mutable in Objective C</h3>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/"><span style="color: #400080;">NSMutableArray</span></a> <span style="color: #002200;">*</span>marr <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/"><span style="color: #400080;">NSMutableArray</span></a> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>marr addObject<span style="color: #002200;">:</span><span style="color: #2400d9;">10</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>marr addObject<span style="color: #002200;">:</span><span style="color: #2400d9;">20</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>marr addObject<span style="color: #002200;">:</span><span style="color: #2400d9;">30</span><span style="color: #002200;">&#93;</span>;<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> <span style="color: #002200;">*</span>arr <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> arrayWithArray<span style="color: #002200;">:</span>marr<span style="color: #002200;">&#93;</span>;</div></div>
<h3>Array Associativi in Objective C</h3>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span style="color: #400080;">NSMutableDictionary</span></a> <span style="color: #002200;">*</span>mdictionary <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span style="color: #400080;">NSMutableDictionary</span></a> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>dictionary setObject<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Number of effs I give on this example&quot;</span><span style="color: #002200;">&#93;</span>;<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/"><span style="color: #400080;">NSDictionary</span></a> <span style="color: #002200;">*</span>dictionary <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/"><span style="color: #400080;">NSDictionary</span></a> dictionaryWithDictionary<span style="color: #002200;">:</span>mdictionary<span style="color: #002200;">&#93;</span>;</div></div>
<h3>Casting in AS3 / Objective C</h3>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> someObject:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> castedAsString:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>someObject<span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/"><span style="color: #400080;">NSObject</span></a> <span style="color: #002200;">*</span>someObject <span style="color: #002200;">=</span> <span style="color: #11740a; font-style: italic;">//pretend I know how to say new();</span><br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>castedAsString <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>someObject;</div></div>
<h3>Primitive in AS3/Objective C</h3>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">AS3 &nbsp; &nbsp; Objective<span style="color: #002200;">-</span>C<br />
<span style="color: #a61390;">true</span>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">YES</span><br />
<span style="color: #a61390;">false</span> &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">NO</span><br />
null&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">nil</span><br />
this&nbsp; &nbsp; &nbsp; &nbsp; self</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/actionscript-3-versus-objective-c-vediamo-le-principali-differenze-a-livello-di-sintassi-del-codice.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firewall: IP Tables un esempio su Linux</title>
		<link>http://www.fimietta.it/blog/firewall.html</link>
		<comments>http://www.fimietta.it/blog/firewall.html#comments</comments>
		<pubDate>Wed, 11 Jan 2012 00:02:37 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Sicurezza dei Sistemi Informatici]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2132</guid>
		<description><![CDATA[Un firewall (dall&#8217;inglese muro anticendio) è necessario perché le reti sono contigue l&#8217;una all&#8217;altra tramite dispositivi di rete router o switch. Se una rete viene attaccata, dobbiamo trovare un meccanismo che ci permetta di impedire che tale l&#8217;attacco si propaghi anche nella altre reti.
Il punto dove si posiziona un firewall non è tra internet e [...]]]></description>
			<content:encoded><![CDATA[<p>Un<strong> firewall</strong> (dall&#8217;inglese muro anticendio) è necessario perché le reti sono contigue l&#8217;una all&#8217;altra tramite dispositivi di rete <strong>router o switch</strong>. Se una rete viene attaccata, dobbiamo trovare un meccanismo che ci permetta di impedire che tale l&#8217;attacco si propaghi anche nella altre reti.</p>
<p>Il <strong>punto</strong> dove si posiziona un firewall non è tra internet e la vostra rete (questo è uno dei possibili punti) ma in termini più generali si posiziona tra due reti <strong>con due livelli di sicurezza differenti</strong>.</p>
<p>La rete con maggior sicurezza viene chiamata &#8220;<strong>rete interna</strong>&#8221; mentre quella con minor livello di sicurezza &#8220;<strong>rete esterna</strong>&#8220;.</p>
<p>Quindi un firewall si posiziona in tutti i punti in cui ci siano <strong>due livelli di sicurezza</strong> differenti.</p>
<p>Attenzione che un firewall ci protegge solo dove è chiuso, dove è aperto non ci protegge per niente.</p>
<p><span id="more-2132"></span></p>
<h3>Ingress vs Egress Firewall</h3>
<p>Un firewall controlla una comunicazione di tipo bidirezionale. Spesso si distingue la funzionalità di &#8220;<strong>ingress</strong>&#8221; ed &#8220;<strong>egress</strong>&#8221; firewall.</p>
<p>L&#8217;<strong>ingress firewall</strong> gestisce i <strong>collegamenti &#8220;incoming&#8221;</strong> (attenzione collegamenti non pacchetti) &#8211; è il tipico caso che si verifica quando dall&#8217;esterno vogliano comunicare con la nostra macchina. Ad esempio, aprire un canale TCP verso il mio server WEB è INGRESS.</p>
<p>Nell&#8217;<strong>egress firewall</strong> si gestiscono i collegamenti &#8220;outgoing&#8221; e si controlla l&#8217;attività del personale.<br />
Questa per le aziende, è un attività importante perché è anche responsabile civile l&#8217;amministratore delegato dell&#8217;azienda stessa.</p>
<p>La distinzione tra INGRESS / EGRESS firewall è molto semplice per tutti quei servizi orientati ai client. In tutte le applicazioni basati su TCP (connection oriented), chi inizia il collegamento è colui che manda il pacchetto SYN. Se invece si utilizza un protocollo connectionless come UDP, determinare la direzione del collegamento non è banale. Inoltre, siccome UDP non è affidabile, non è detto che cisano tutti i datagrammi e risulta molto più complicato determinare il termine della comunicazione.</p>
<h3>I tre comandamenti del firewall (D.Cheswick e S.Bellowin)</h3>
<ol>
<li>Il FIREWALL deve essere l&#8217;unico punto di contatto della rete interna con quella esterna</li>
<li>Solo il traffico autorizzato può attraversare il FIREWALL</li>
<li>Il FIREWALL deve essere un sistema altamente sicuro esso stesso</li>
</ol>
<p>Il primo &#8220;comandamento&#8221; ci indica che il firewall deve essere l&#8217;unico punto di contatto tra la rete interna ed esterna. Si pensi al caso in cui i dipendenti usano le chiavette per collegarsi ad internet per navigare su siti come Facebook. Questo per il gestore della sicurezza aziendale è un vero incubo perché quel traffico non è protetto da firewall e quindi potenzialmente attaccabile dai &#8220;cattivi&#8221;. Un altro caso comune, è collegarsi a una rete wifi vicina che non è protetta per navigare su internet.</p>
<p>Il secondo &#8220;comandamento&#8221; ci dice che solo il traffico autorizzato può attraversare il FIREWALL &#8211; ma cosa vuol dire esattamente &#8220;autorizzato&#8221; ? Non è semplice definirlo.</p>
<p>Il terzo comandamento dice che il firewall deve essere un sistema altamente sicuro esso stesso,nel senso che DEVE avere SOLO quel compito. Su un firewall non bisogna mettere su altri software che non è quello di sicurezza, perché se quel software ha un baco, l&#8217;attaccante entra nel FIREWALL stesso.<br />
I componenti del firewall devono essere elementi dedicati e sicuri.</p>
<h3>L&#8217;indicie della sicurezza</h3>
<p>Più aumenta la sicurezza e meno abbiamo la funzionalità.<br />
Più aumenta la funzionalità meno abbiamo la sicurezza.</p>
<h3>Politiche di autorizzazione</h3>
<p>Esistono due politiche di autorizzazione:</p>
<ol>
<li>Tutto ciò che non è espressamente permesso è vietato</li>
<li>Tutto ciò che non è espressamente vietato è permesso</li>
</ol>
<p>Nella prima si ha maggior sicurezza ma è più difficile da gestire.<br />
Nella seconda si ha minor sicurezza (porte aperte) ma è più facile da gestire.</p>
<p>Tra le due, la migliore è la prima: questa cosa è permessa e tutto il resto è vietato. Se non ci serve una porta, perché aprirla? Potrebbe essere fonte di problema.</p>
<h3>Considerazioni sui Firewall</h3>
<p>In generale è consigliabile creare un sistema semplice applicando la regola KISS (Keep It Simple Stupid) poiché più un sistema è complicato più è difficile da verificare.</p>
<p>Ad esempio, l&#8217;inventore di DJBDNS ha usato la regola KISS applicandola anche alle librerie. Nel momento in cui ad esempio in c utilizziamo la funzione strcopy, in realtà includiamo la string.h (ma tutte le altre funzione della string.h non ci servono!!!). Questa è una buona regola di programmazione sicura.</p>
<p>Un software contiene certamente dei bachi. Se il programma viene mandato in esecuzione, diventa un processo e di conseguenza un problema di sicurzza.<br />
Sul firewall bisogna far girare i processi essenziali. Questo è un lavoro molto importante difficile da applicare su sistemi operativi come Windows poiché è complicato capire cosa fanno i processi.<br />
Per questo motivo i firewall si fanno con Linux.</p>
<p>Un firewall non è una macchina general purposte, quindi no software e no utenti.</p>
<p>Il principio è che ognuno è colpevole finché non si dimostra che è innocente (per le persone il principio è il contrario <img src='http://www.fimietta.it/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> )</p>
<h3>IPTABLES</h3>
<p><strong>IP Tables</strong> fornisce funzionalità di manipolazione e filtraggio di pacchetti IP. IPtables si basa sul <strong>concetto di &#8220;chain&#8221;.</strong><br />
Ma che cos&#8217;è una chain? Una <strong>chain</strong> non è altro che una <strong>lista ordinata di regole</strong> a cui è associata una <strong>politica di default</strong>.<br />
Esistono, per il filtraggio dei pacchetti, tre catene predefinite:</p>
<ul>
<li><strong>INPUT</strong>, contiene le regole che devono essere applicate <em>ai pacchetti diretti alla macchina su cui è installato IPtables</em> che si sta configurando;
</li>
<li><strong>OUTPUT</strong>, contiene le regole che devono essere applicate <em>ai pacchetti in uscita dalla macchina su cui è installato IPtables</em> che si sta configurando;
</li>
<li><strong>FORWARD</strong>, contiene le regole che devono essere applicate ai pacchetti che non provengono e non sono diretti alla macchina su cui e` installato IPtables ma che, se l’IP forwarding è abilitato, verranno inoltrati verso una specifica interfaccia.</li>
</ul>
<h3>Come configurare IPTABLES</h3>
<p><strong>IPtables </strong>può essere configurato con il comando <strong>iptables</strong> (man iptables per maggiori informazioni). Di seguito una lista dei principali comandi:</p>
<ul>
<li>l’opzione -P chain target permette di modificare la politica di autorizzazione di default della cate- na chain (INPUT, OUTPUT, FORWARD o personalizzate) impostandola al valore target </li>
<li>-A chain e -I chain permettono di aggiunge una nuova regola rispettivamente in coda e in testa alla<br />
catena chain;</li>
<li>-D chain e -R chain permettono di cancellare o sostituire una regola in chain (tramite l’ordinale, se e`<br />
noto, o tramite un indirizzo IP);</li>
<li>
-F [chain] cancella tutte le regole presenti in chain o tutte le catene, se non viene specificato il valore<br />
di chain (attenzione: la politica di default non viene pero` modificata).</li>
<li>
-N chain crea una nuova catena di nome chain;
</li>
<li>-X chain cancella la catena chain, creata dall’utente.</li>
</ul>
<p>Si mostra di seguito l’utilizzo del comando necessario a re-inizializzare tutte le catene:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-F</span></div></div>
<p>oppure solo una, quella passata come parametro (in questo caso quella di OUTPUT):</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-F</span> OUTPUT</div></div>
<p>Quando si specifica una regola di filtraggio, è necessario fare riferimento a diverse <strong>porzioni del pacchetto IP</strong>.<br />
Per questo <strong>IP Tables</strong> mette a disposizione una serie di comandi (la lista completa disponibile tramite man):</p>
<ul>
<li>-s IP source, indirizzo IP sorgente;</li>
<p>
<li>-d IP dest, indirizzo IP destinazione;</li>
<p>
<li> &#8211;sport porta, porta sorgente;</li>
<p>
<li>&#8211;dport porta, porta destinazione;</li>
<p>
<li> -i interfaccia, interfaccia di invio/ricezione del pacchetto (catena di INPUT);</li>
<p>
<li>-o interfaccia, interfaccia di invio/ricezione del pacchetto (catena di OUTPUT);</li>
<p>
<li> -p proto, protocollo (es. tcp, udp);</li>
<p>
<li>-j azione, azione da intraprendere (il target in terminologia IP Tables);</li>
<p>
<li>-y o &#8211;syn, nel caso di opzione -p tcp, identifica un pacchetto con (solo) il flag SYN abilitato;</li>
<p>
<li>&#8211;icmp-type tipo, equivalente a -p icmp, tipo specifica il tipo di pacchetto ICMP</li>
<p>
<li>-l, abilita il log del risultato della valutazione di una regola in tramite syslog in /var/log/messages</li>
</ul>
<h3>Azioni sui pacchetti</h3>
<p>Le azioni da intraprendere, in terminologia <strong>IP Tables</strong> i “<strong>target</strong>” sono i seguenti:<br />
</p>
<ul>
<li> <strong>ACCEPT</strong>, accetta il pacchetto;</li>
<li><strong>DROP</strong>, scarta il pacchetto e non invia notifica;</li>
<li> <strong>REJECT</strong>, scarta il pacchetto ma invia una notifica, sconsigliato nella maggior parte dei casi perché accelera<br />
le procedure di scanning. Di default, viene inviato un pacchetto di tipo “ICMP port unreachable”, tuttavia<br />
questo pu`o essere cambiato impostando l’opzione &#8211;reject-with;
</li>
<li> <strong>RETURN</strong>, impone l’applicazione della default action anche se non `e stata esaminata tutta la catena.</li>
</ul>
<h3>Visualizzare lo stato del Firewall</h3>
<p>Per visualizzare lo stato del firewall:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-L</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-v</span></div></div>
<p>dove -L sta per List rules, -v per ottenere delle informazioni dettagliate mentre -n visualizza gli indirizzi ip e le porte in formato numerico senza usare un server DNS per risolvere i nomi.</p>
<h3>Esempi di configurazione IP TABLES</h3>
<p>Per bloccare un&#8217;indirizzo ip (esempio un attaccante):</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 1.2.3.4 <span style="color: #660033;">-j</span> DROP</div></div>
<p>dove 1.2.3.4 è l&#8217;indirizzo ip della macchina che vogliamo bloccare.</p>
<p>Per bloccare un dominio (es. Facebook.com):</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> www.facebook.com <span style="color: #660033;">-j</span> DROP<br />
iptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> facebook.com <span style="color: #660033;">-j</span> DROP</div></div>
<p>Per bloccare le richieste ICMP:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">--icmp-type</span> echo-request <span style="color: #660033;">-j</span> DROP<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> eth1 <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">--icmp-type</span> echo-request <span style="color: #660033;">-j</span> DROP</div></div>
<p>Aprire un range di porte:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">7000</span>:<span style="color: #000000;">7010</span> <span style="color: #660033;">-j</span> ACCEPT</div></div>
<p>Aprire / Chiudere porte comuni:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:800px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Replace ACCEPT with DROP to block port:<br />
<span style="color: #666666; font-style: italic;">## open port ssh tcp port 22 ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open cups (printing service) udp/tcp port 631 for LAN users ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-p</span> udp <span style="color: #660033;">-m</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">631</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">631</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## allow time sync via NTP for lan users (open udp port 123) ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">123</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open tcp port 25 (smtp) for all ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">25</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;"># open dns server ports for all ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open http/https (Apache) server port to all ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open tcp port 110 (pop3) for all ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">110</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open tcp port 143 (imap) for all ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">143</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open access to Samba file server for lan users only ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">137</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">138</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">139</span> <span style="color: #660033;">-j</span> ACCEPT<br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">445</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open access to proxy server for lan users only ##</span><br />
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">3128</span> <span style="color: #660033;">-j</span> ACCEPT<br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">## open access to mysql server for lan users only ##</span><br />
iptables <span style="color: #660033;">-I</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">3306</span> <span style="color: #660033;">-j</span> ACCEPT</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/firewall.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Una piccola introduzione al framework php Yii (Yes It Is!) &#8211; installazione e creazione di una semplice applicazione web 2.0</title>
		<link>http://www.fimietta.it/blog/una-piccola-introduzione-al-framework-php-yii-installazione-e-creazione-di-una-semplice-applicazione-web-2-0.html</link>
		<comments>http://www.fimietta.it/blog/una-piccola-introduzione-al-framework-php-yii-installazione-e-creazione-di-una-semplice-applicazione-web-2-0.html#comments</comments>
		<pubDate>Tue, 10 Jan 2012 23:50:33 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2729</guid>
		<description><![CDATA[Yii è un framework open source scritto in PHP pensato per sviluppare applicazioni web 2.0.
Yii implementa il pattern architetturale MVC (MODEL VIEW CONTROLLER) che ha come obiettivo principale quello di separare la logica di business da interfaccia utente.
Secondo questo noto pattern, nel MODEL sono memorizzati i dati dell&#8217;applicazione, nel VIEW sono visualizzati gli elementi dell&#8217;interfaccia [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Yii</strong> è un framework open source scritto in PHP pensato per sviluppare applicazioni web 2.0.</p>
<p><strong>Yii</strong> implementa il <strong>pattern architetturale MVC (MODEL VIEW CONTROLLER) </strong>che ha come obiettivo principale quello di separare la <strong>logica di business</strong> da <strong>interfaccia utente</strong>.</p>
<p>Secondo questo noto pattern, nel <strong>MODEL</strong> sono memorizzati i dati dell&#8217;applicazione, nel <strong>VIEW</strong> sono visualizzati gli elementi dell&#8217;interfaccia utente ed i dati contenuti nel model mentre il <strong>CONTROLLER</strong> gestisce principalmente la comunicazione tra <strong>MODEL e VIEW</strong>.</p>
<p>In altre parole la <strong>logica applicativa</strong> è a carico del <strong>MODEL / CONTROLLER</strong> mentre l&#8217;interfaccia utente è a carico della <strong>VIEW</strong>. Questo pattern aiuta i programmatori ad avere un codice organizzato e più facile da manutenere.</p>
<p>Oltre ad implementare il <strong>design-pattern MVC</strong>, <strong>Yii</strong> ha introdotto un ulteriore <strong>front-controller</strong> chiamato <strong>Application</strong> che funge da router di tutte le richieste web. Il <strong>front-controller</strong> analizza le richieste provenienti dal browser ed estrapola alcune informazioni utili per capire a quale <strong>controller</strong> inoltrarle.</p>
<p><span id="more-2729"></span></p>
<p>In figura è riportata la struttura di una generica applicazione Yii:</p>
<table>
<tr>
<td>
<div id="attachment_2731" class="wp-caption alignleft" style="width: 410px"><a href="http://www.fimietta.it/blog/wp-content/uploads/2012/01/struttura-di-un-applicazione-yii.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/01/struttura-di-un-applicazione-yii.png" alt="struttura-di-un-applicazione-yii" title="struttura-di-un-applicazione-yii" width="400" height="300" class="size-full wp-image-2731" /></a><p class="wp-caption-text">struttura-di-un-applicazione-yii</p></div>
</td>
</tr>
</table>
<h3>Ciclo di vita di una richiesta WEB all&#8217;interno del framework Yii</h3>
<ol>
<li>Il browser invia una richiesta al server che ospita l&#8217;applicazione con MVC</li>
<li>Un controllore è invocato per gestire la richiesta</li>
<li>Il controllore interagisce con il modello</li>
<li>Il controllore invoca la view</li>
<li>La view renderizza i dati sottoforma di HTML e li restituisce al browser</li>
</ol>
<h3>Convenzione sull&#8217;URL</h3>
<p>Come già detto, in un&#8217;applicazione Yii le richieste proveniente dal browser sono prima elaborate da un ROUTER che analizza la richiesta per decidere a quale applicazione inoltrarla.</p>
<p>Il router prende la decisione su quale controllore invocare in base alla struttura della URL che deve seguire questa convenzione:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http:<span style="color: #000000; font-weight: bold;">//</span>hostname<span style="color: #000000; font-weight: bold;">/</span>index.php?<span style="color: #007800;">r</span>=ControllerID<span style="color: #000000; font-weight: bold;">/</span>ActionID</div></div>
<p>Dove la variabile GET <strong>r</strong> si riferisce alla <strong>route</strong> che sarà risolta dal router di Yii nel corrispondente <strong>controllore / azione</strong>.<br />
Se l&#8217;<strong>ActionID</strong> è omesso viene chiamato quella di default e lo stesso discorso vale per <strong>ControllerID</strong>.</p>
<p>Esempio:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http:<span style="color: #000000; font-weight: bold;">//</span>www.example.com<span style="color: #000000; font-weight: bold;">/</span>index.php?<span style="color: #007800;">r</span>=post<span style="color: #000000; font-weight: bold;">/</span>show<span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #007800;">id</span>=<span style="color: #000000;">1</span></div></div>
<p>Se avete intenzione di indicizzare il vostro sito sui motori di ricerca, una delle principali <strong>regole SEO</strong> da seguire è l&#8217;avere degli <strong>SEO Friendly URLs</strong> (esempio con questa struttura &#8211; <strong>http://hostname/ControllerID/ActionID.html</strong>). Per far cio&#8217; vi può essere di aiuto <strong><a href="http://www.yiiframework.com/doc/api/1.1/CUrlManager" target="_blank">cUrlManager</a></strong></p>
<p>Le <strong>convenzioni</strong> sono molto utilizzate all&#8217;interno di questo framework, questo perché Yii favorisce il paradigma di programmazione &#8220;<strong>conventions over configurations</strong>&#8221; (<a href="http://it.wikipedia.org/wiki/Convention_Over_Configuration " target="_blank">http://it.wikipedia.org/wiki/Convention_Over_Configuration</a>)</p>
<h3>Convenzione sulle directory</h3>
<p>Nel momento in cui si crea un&#8217;applicazione con Yii bisogna seguire delle convenzioni sui nomi delle directory (queste convenzioni posso essere modificate):</p>
<ul>
<li><strong>WebRoot/protected</strong>: questa è la <strong>cartella principale dell&#8217;applicazione</strong> che contiene tutti gli script PHP sensibili alla sicurezza ed i file dei dati.</li>
<li><strong>WebRoot/protected/runtime</strong>: contiene i file temporanei privati generati durante l&#8217;esecuzione dell&#8217;applicazione</li>
<li><strong>WebRoot/protected/extensions</strong>:contiene tutte le estensioni di terze parti.</li>
<li><strong>WebRoot/protected/modules</strong>: contiene tutti i moduli dell&#8217;applicazione</li>
<li><strong>WebRoot/protected/controllers</strong>: contiene tutti i file delle classi controller.</li>
<li><strong>WebRoot/protected/views</strong>: contiene tutti i file delle view, comprese le view dei controller, le view dei layout e le view di sistema.</li>
<li><strong>WebRoot/protected/views/ControllerID</strong>: questa cartella contiene i file delle view di una singola classe controller. </li>
<li><strong>WebRoot/protected/views/layouts</strong>: contiene tutti i file delle view dei layout. </li>
<li><strong>WebRoot/protected/views/system</strong>: contiene tutti i file delle view delle view di sistema. </li>
<li><strong>WebRoot/assets</strong>: contiene tutti i file asset pubblicati.</li>
<li><strong>WebRoot/themes</strong>: contiene vari temi che possono essere applicati all&#8217;applicazione. Ciascuna sotto cartella rappresenta un singolo tema il cui nome è il nome della sottocartella.</li>
</ul>
<h3>Installare il Framework Yii in Windows 7 con XAMPP e creare la prima applicazione demo</h3>
<ul>
<li>Scaricare Yii framework dal sito ufficiale -<a href="http://www.yiiframework.com" title="Yii Framework" target="_blank"> http://www.yiiframework.com</a></li>
<li>Scompattare l&#8217;archivio e salvare la cartella <strong>framework</strong> all&#8217;interno della root del server web, nel mio caso <strong>c:\xamplite\htdocs</strong></li>
<li>
Modificare la <strong>variabile d&#8217;ambiente</strong> di sistema <strong>PATH</strong> aggiungendo due valori: il primo è il <em>percorso del framework</em> &#8211; <em>c:\xamplite\htdocs\framework</em> mentre il secondo è il <em>percorso dell&#8217;eseguibile php</em> che nel mio caso è <strong>c:\xamplite\php</strong>:</p>
<table>
<tr>
<td>
<a href="http://www.fimietta.it/blog/wp-content/uploads/2012/01/modifica_variabile_sistema_yii.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/01/modifica_variabile_sistema_yii.png" alt="modifica_variabile_sistema_yii" title="modifica_variabile_sistema_yii" width="594" height="622" class="alignleft size-full wp-image-2734" />
</td>
</tr>
</table>
<p></a>
</li>
<li>aprire il prompt dei comandi e spostarsi all&#8217;interno della propria webroot, nel mio caso c:\xamplite\htdocs: ed eseguire l&#8217;<strong>utility yiic </strong>per creare una nuova applicazione demo impartendo il comando
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">yiic webapp demo</div></div>
<p>come mostrato in figura:<br />
<a href="http://www.fimietta.it/blog/wp-content/uploads/2012/01/screenshot_esecuzione_comando_yiic1.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/01/screenshot_esecuzione_comando_yiic1.png" alt="screenshot_esecuzione_comando_yiic" title="screenshot_esecuzione_comando_yiic" width="600" height="583" class="alignleft size-full wp-image-2738" /></a></p>
</li>
</ul>
<h3>Ecco come si presenta all&#8217;applicazione demo appena creata</h3>
<p><a href="http://www.fimietta.it/blog/wp-content/uploads/2012/01/screenshot_prima_applicazione_con_yii.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/01/screenshot_prima_applicazione_con_yii.png" alt="screenshot_prima_applicazione_con_yii" title="screenshot_prima_applicazione_con_yii" width="600" height="516" class="alignleft size-full wp-image-2743" /></a></p>
<p>L&#8217;applicazione appena creata dal tool <strong>yiic</strong> è composta da quattro pagine:</p>
<ol>
<li>Home &#8211; http://localhost/demo/index.php?r=<strong>site</strong>/<strong>index</strong> </li>
<li>About &#8211; http://localhost/demo/index.php?r=<strong>site</strong>/<strong>page</strong>&#038;view=about </li>
<li>Contact &#8211; http://localhost/demo/index.php?r=<strong>site</strong>/<strong>contact</strong> </li>
<li>Login &#8211; http://localhost/demo/index.php?r=<strong>site</strong>/<strong>login</strong> </li>
</ol>
<p><strong>Home</strong> richiama l&#8217;azione <strong>index</strong> contenuta nel controller <strong>site</strong>, <strong>About</strong> richiama l&#8217;azione <strong>page</strong> del controller <strong>site</strong> passando come parametro la querystring <strong>&#038;view=about</strong>, <strong>Contact</strong> richiama l&#8217;azione <strong>contact</strong> del controller <strong>site</strong> mentre <strong>Login</strong> richiama l&#8217;azione login del controller <strong>site</strong>. </p>
<p>Per maggiori dettagli sull&#8217;applicazione appena installata: <a href="http://www.yiiframework.com/doc/guide/1.1/en/quickstart.first-app" target="_blank">http://www.yiiframework.com/doc/guide/1.1/en/quickstart.first-app</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/una-piccola-introduzione-al-framework-php-yii-installazione-e-creazione-di-una-semplice-applicazione-web-2-0.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NetBeans IDE: JVM Creation Failed vediamo come risolverlo</title>
		<link>http://www.fimietta.it/blog/netbeans-ide-jvm-creation-failed-vediamo-come-risolverlo.html</link>
		<comments>http://www.fimietta.it/blog/netbeans-ide-jvm-creation-failed-vediamo-come-risolverlo.html#comments</comments>
		<pubDate>Tue, 10 Jan 2012 10:53:18 +0000</pubDate>
		<dc:creator>fimietta</dc:creator>
				<category><![CDATA[Utilità]]></category>

		<guid isPermaLink="false">http://www.fimietta.it/blog/?p=2722</guid>
		<description><![CDATA[Ho appena installato su un sistema operativo Windows 7 a 64bit l&#8217;albiente IDE NetBeans per programmare con PHP .
Fin dal primo avvio, NetBeans mi ha segnalato il seguente errore:








Per risolvere il problema bisogna modificare tramite un editor di testo come Notepad o PSPAD un file di configurazione chiamato netbeans.conf che si trova all&#8217;interno della cartella [...]]]></description>
			<content:encoded><![CDATA[<p>Ho appena installato su un sistema operativo Windows 7 a 64bit l&#8217;albiente<strong> IDE NetBeans</strong> per programmare con<strong> PHP</strong> .<br />
Fin dal primo avvio, NetBeans mi ha segnalato il seguente errore:</p>
<table>
<tr>
<td>
<div id="attachment_2723" class="wp-caption alignleft" style="width: 480px"><a href="http://www.fimietta.it/blog/wp-content/uploads/2012/01/netbeans_errore_jvm_creation_failed.png"><img src="http://www.fimietta.it/blog/wp-content/uploads/2012/01/netbeans_errore_jvm_creation_failed.png" alt="netbeans_errore_jvm_creation_failed" title="netbeans_errore_jvm_creation_failed" width="470" height="299" class="size-full wp-image-2723" /></a><p class="wp-caption-text">netbeans_errore_jvm_creation_failed</p></div>
</td>
</tr>
</table>
<p>
<span id="more-2722"></span><br />
Per risolvere il problema bisogna modificare tramite un editor di testo come Notepad o PSPAD un file di configurazione chiamato <strong>netbeans.conf</strong> che si trova all&#8217;interno della cartella <strong>etc</strong> contenuta nel direttorio di installazione del programma  (nel mio caso <em>C:\Program Files (x86)\NetBeans 7.1\etc</em>).</p>
<p>La riga incriminata è la seguente:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">netbeans_default_options</span>=<span style="color: #ff0000;">&quot;-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true&quot;</span></div></div>
<p>Bisogna modificarla aggiungendo questa opzione:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">-J-XX:<span style="color: #007800;">MaxPermSize</span>=128m</div></div>
<p>Quindi la riga finale diventa:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">netbeans_default_options</span>=<span style="color: #ff0000;">&quot;-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=128m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true&quot;</span></div></div>
<p>Salvate e buon lavoro con NetBeans <img src='http://www.fimietta.it/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.fimietta.it/blog/netbeans-ide-jvm-creation-failed-vediamo-come-risolverlo.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
