<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[framework]]></title><description><![CDATA[<p dir="auto">Buonasera a tutti,</p>
<p dir="auto">volevo avvicinarmi ad un framework per fare prima a sviluppare dei progetti;</p>
<p dir="auto">ho scelto così codeigniter+grocery CRUD che mi è un po' più familiare, premetto che sono un principiante di php;</p>
<p dir="auto">qualcuno lo usa? di fatto riesco a fare delle pagine statiche, faccio il controller, gli array e li passo ad una view;</p>
<p dir="auto">ora vorrei fare un amministrazione, e con delle query estrarre i dati; ho installato grocery CRUD,</p>
<p dir="auto">ho aperto il controller, view e l model ma non mi è molto chiaro come procedere <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/customizations/ad0a1f8d-b404-40e4-a46a-e563b14044da-dho.gif?v=12b9555a9a1" class="not-responsive emoji emoji-customizations emoji--arrabbiato" style="height:1.4em;width:auto;vertical-align:middle" title=":x" alt="" /></p>
<p dir="auto">Avete dei consigli? Guide in Italiano?</p>
<p dir="auto">Ringrazio in anticipo<br />
Buona Serata</p>
]]></description><link>https://dev.connect.gt/topic/210938/framework</link><generator>RSS for Node</generator><lastBuildDate>Thu, 26 Nov 2026 02:34:00 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/210938.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 10 Feb 2015 19:07:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to framework on Tue, 03 Mar 2015 14:25:55 GMT]]></title><description><![CDATA[<p dir="auto">Ciao Thedarkita,</p>
<p dir="auto">dunque... continuo qui la discussione su codeigniter,</p>
<p dir="auto">posto il codice della home:</p>
<p dir="auto">home.php (controller)</p>
<pre><code class="language-php">&lt;?php	class home extends CI_Controller {    	public function index(){			$this-&gt;load-&gt;model("home_model");            $dati['elementi'] = $this-&gt;home_model-&gt;get_dati(); // array                        $metatag['title'] = 'title';    		$metatag['description'] = 'description';    		$metatag['keywords'] = 'keywords';
    		$this-&gt;load-&gt;view('header', $metatag);            $this-&gt;load-&gt;view('home',$dati);            $this-&gt;load-&gt;view('footer');       }    }
</code></pre>
<p dir="auto">home_model.php (model)</p>
<pre><code class="language-php">&lt;?php	class home_model extends CI_Model {       	function __construct(){parent::__construct();}    	function get_dati(){    	   $query = $this-&gt;db-&gt;order_by('data desc')-&gt;get('articoli');    	   return $query-&gt;result();      	}	}
</code></pre>
<p dir="auto">home.php (view)</p>
<pre><code class="language-php">&lt;!DOCTYPE html&gt;&lt;html lang="en"&gt;&lt;head&gt;&lt;meta charset="utf-8" /&gt;&lt;title&gt;Home&lt;/title&gt;&lt;/head&gt;&lt;body&gt;    &lt;?php    foreach ($elementi as $key =&gt; $value) {        echo "&lt;strong&gt;ID&lt;/strong&gt;: ".$value-&gt;id."&lt;br /&gt;";        echo "&lt;strong&gt;ID Categoria&lt;/strong&gt;: ".$value-&gt;categoria_id."&lt;br /&gt;";         echo "&lt;strong&gt;Title&lt;/strong&gt;: ".$value-&gt;title."&lt;br /&gt;";        echo "&lt;strong&gt;Description&lt;/strong&gt;: ".$value-&gt;description."&lt;br /&gt;";        echo "&lt;strong&gt;Keywords&lt;/strong&gt;: ".$value-&gt;keywords."&lt;br /&gt;";        echo "&lt;strong&gt;Data&lt;/strong&gt;: ".$value-&gt;data."&lt;br /&gt;";        echo "&lt;strong&gt;Titolo&lt;/strong&gt;: ".$value-&gt;h1."&lt;br /&gt;";        echo "&lt;strong&gt;Sottotitolo&lt;/strong&gt;: ".$value-&gt;h2."&lt;br /&gt;";        echo "&lt;strong&gt;Testo&lt;/strong&gt;: ".$value-&gt;testo."&lt;br /&gt;";        echo "&lt;strong&gt;Visibile&lt;/strong&gt;: ".$value-&gt;visibile."&lt;br /&gt;";        echo "&lt;br /&gt;";        echo "&lt;hr&gt;";        echo "&lt;br /&gt;";    }        ?&gt;&lt;/body&gt;&lt;/html&gt;
</code></pre>
<p dir="auto">di fatto mi da tutti i record della tabella "articoli";<br />
ora vorrei inserire un link nel titolo dell'articolo per andare nel dettaglio e vedere solo quello;</p>
<p dir="auto">come si fa? <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/customizations/ad0a1f8d-b404-40e4-a46a-e563b14044da-dho.gif?v=12b9555a9a1" class="not-responsive emoji emoji-customizations emoji--arrabbiato" style="height:1.4em;width:auto;vertical-align:middle" title=":x" alt="" /></p>
<p dir="auto">grazie 1000<br />
buona giornata</p>
]]></description><link>https://dev.connect.gt/post/1189165</link><guid isPermaLink="true">https://dev.connect.gt/post/1189165</guid><dc:creator><![CDATA[enricocarli]]></dc:creator><pubDate>Tue, 03 Mar 2015 14:25:55 GMT</pubDate></item><item><title><![CDATA[Reply to framework on Fri, 20 Feb 2015 18:05:49 GMT]]></title><description><![CDATA[<p dir="auto">grazie mille Thedarkita!!</p>
<p dir="auto">funziona ancora e c'è meno codice, meglio credo <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=12b9555a9a1" class="not-responsive emoji emoji-android emoji--smile" style="height:1.4em;width:auto;vertical-align:middle" title=":D" alt="😄" /></p>
<p dir="auto">buon week end<br />
a risentirci!</p>
]]></description><link>https://dev.connect.gt/post/1189163</link><guid isPermaLink="true">https://dev.connect.gt/post/1189163</guid><dc:creator><![CDATA[enricocarli]]></dc:creator><pubDate>Fri, 20 Feb 2015 18:05:49 GMT</pubDate></item><item><title><![CDATA[Reply to framework on Thu, 19 Feb 2015 19:18:07 GMT]]></title><description><![CDATA[<p dir="auto">Prego,<br />
una cosa però non fare questo:</p>
<pre><code>[COLOR=#007700][FONT=monospace]function [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get_dati[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()
    {
       [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]db[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]select[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'*'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
       [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]db[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]from[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'actor'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
       [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$query [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]db[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get[/FONT][/COLOR][COLOR=#007700][FONT=monospace]();
      
       foreach ([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$query[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]result[/FONT][/COLOR][COLOR=#007700][FONT=monospace]() as [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$row[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
       {
             [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$return[/FONT][/COLOR][COLOR=#007700][FONT=monospace][] = [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$row[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
       }
        return [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$return[/FONT][/COLOR][COLOR=#007700][FONT=monospace];                 
    }[/FONT][/COLOR]
</code></pre>
<p dir="auto">Perchè è sufficiente(E migliore prestazionalmente) fare questo:</p>
<pre><code>[COLOR=#007700][FONT=monospace]function [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get_dati[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()
    {
       [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]db[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]select[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'*'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
       [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]db[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]from[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'actor'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
       [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$query [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]db[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get[/FONT][/COLOR][COLOR=#007700][FONT=monospace]();[/FONT][/COLOR][COLOR=#007700][FONT=monospace]
        return [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$query[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]result[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()[/FONT][/COLOR][COLOR=#007700][FONT=monospace];  
[/FONT][/COLOR]}
</code></pre>
<p dir="auto">E volendo proprio essere pignoli:</p>
<pre><code>[COLOR=#007700][FONT=monospace]function [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get_dati[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()
    {
       $query = [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]db[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'actor'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);[/FONT][/COLOR][COLOR=#007700][FONT=monospace]
       return [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$query[/FONT][/COLOR][COLOR=#007700][FONT=monospace]-&gt;[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]result[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()[/FONT][/COLOR][COLOR=#007700][FONT=monospace];  
[/FONT][/COLOR]}
</code></pre>
]]></description><link>https://dev.connect.gt/post/1189157</link><guid isPermaLink="true">https://dev.connect.gt/post/1189157</guid><dc:creator><![CDATA[thedarkita]]></dc:creator><pubDate>Thu, 19 Feb 2015 19:18:07 GMT</pubDate></item><item><title><![CDATA[Reply to framework on Thu, 19 Feb 2015 19:02:46 GMT]]></title><description><![CDATA[<p dir="auto">Grazie Thedarkita,</p>
<p dir="auto">avevi ragione su tutto, grazie infinite <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=12b9555a9a1" class="not-responsive emoji emoji-android emoji--smile" style="height:1.4em;width:auto;vertical-align:middle" title=":D" alt="😄" /> comincio a capirci qualcosa;</p>
<p dir="auto">posto il codice nel caso a qualcuno fosse utile.</p>
<p dir="auto">ci si sente presto mi sa <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=12b9555a9a1" class="not-responsive emoji emoji-android emoji--smile" style="height:1.4em;width:auto;vertical-align:middle" title=":D" alt="😄" /><br />
buona serata a tutti</p>
<p dir="auto"><strong>actor_model.php</strong></p>
<pre><code class="language-php">&lt;?php
class actor_model extends CI_Model {
    var $actor_id   = '';
    var $fullname = ''; 
    var $last_update = '';
   
    function __construct()
        {parent::__construct();}
  
   function get_dati()
    {
       $this-&gt;db-&gt;select('*');
       $this-&gt;db-&gt;from('actor');
       $query = $this-&gt;db-&gt;get();
      
       foreach ($query-&gt;result() as $row)
       {
             $return[] = $row;
       }
        return $return;                 
    }
}
</code></pre>
<p dir="auto"><strong>actor.php (CONTROLLER)</strong></p>
<pre><code class="language-php">&lt;?php
class actor extends CI_Controller {
       public function index()
       {
             $this-&gt;load-&gt;model("actor_model");
             //$dati['title'] = "title"; // variabile

             $dati['elementi'] = $this-&gt;actor_model-&gt;get_dati(); // array
            
             $this-&gt;load-&gt;view('actor',$dati);
       }
}
</code></pre>
<p dir="auto"><strong>actor.php (VIEW)</strong></p>
<pre><code class="language-php">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8" /&gt;
&lt;title&gt;Actor&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;?php
    foreach ($elementi as $key =&gt; $value) {
        echo $value-&gt;actor_id."&lt;br /&gt;";
        echo $value-&gt;fullname."&lt;br /&gt;"; 
        echo $value-&gt;last_update."&lt;br /&gt;&lt;br /&gt;";
    }
    
    ?&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
]]></description><link>https://dev.connect.gt/post/1189164</link><guid isPermaLink="true">https://dev.connect.gt/post/1189164</guid><dc:creator><![CDATA[enricocarli]]></dc:creator><pubDate>Thu, 19 Feb 2015 19:02:46 GMT</pubDate></item><item><title><![CDATA[Reply to framework on Wed, 18 Feb 2015 18:50:50 GMT]]></title><description><![CDATA[<p dir="auto">Ciao,<br />
metti in autoload il database, manca l'istanza per quello hai quell'errore.<br />
Nel controller che hai messo manca anche il richiamo della view a cui passi poi l'array, per cui non vedrai in ogni caso nulla con quel codice nel controller.</p>
]]></description><link>https://dev.connect.gt/post/1189156</link><guid isPermaLink="true">https://dev.connect.gt/post/1189156</guid><dc:creator><![CDATA[thedarkita]]></dc:creator><pubDate>Wed, 18 Feb 2015 18:50:50 GMT</pubDate></item><item><title><![CDATA[Reply to framework on Wed, 18 Feb 2015 18:38:05 GMT]]></title><description><![CDATA[<p dir="auto">Grazie 1000 a tutti per le risposte! <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=12b9555a9a1" class="not-responsive emoji emoji-android emoji--smile" style="height:1.4em;width:auto;vertical-align:middle" title=":D" alt="😄" /></p>
<p dir="auto">ci sto studiando ancora sopra ma alcune cose non mi sono chiarissime <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/customizations/ad0a1f8d-b404-40e4-a46a-e563b14044da-dho.gif?v=12b9555a9a1" class="not-responsive emoji emoji-customizations emoji--arrabbiato" style="height:1.4em;width:auto;vertical-align:middle" title=":x" alt="" /></p>
<p dir="auto">però è comodo, in quando l'amministrazione è già fatta,</p>
<p dir="auto">ci si dedica alle query per estrarre i dati e alle view di fatto, o sbaglio?</p>
<p dir="auto">Una cosa non capisco, provo ad estrarre dei dati dal db, ma non funziona, posto il codice nella speranza che qualcuno possa aiutarmi:</p>
<p dir="auto">actor_model.php (MODEL)</p>
<pre><code class="language-php">&lt;?php
class actor_model extends CI_Model {
    var $actor_id   = '';
    var $fullname = ''; 
    var $last_update = '';
   
    function __construct()
        {parent::__construct();}
  
   function get_dati()
    {
       $this-&gt;db-&gt;select('*');
       $this-&gt;db-&gt;from('actor');
       $query = $this-&gt;db-&gt;get();
      
       foreach ($query-&gt;result() as $row)
       {
             $return[] = $row;
       }
        return $return;                 
    }
}
</code></pre>
<p dir="auto">actor.php (CONTROLLER)</p>
<pre><code class="language-php">&lt;?php
class actor extends CI_Controller {
       public function index()
       {
             $this-&gt;load-&gt;model("actor_model");
             $dati['elementi'] = $this-&gt;actor_model-&gt;get_dati();
       }
}
</code></pre>
<p dir="auto">actor.php (VIEW)</p>
<pre><code class="language-php">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8" /&gt;
&lt;title&gt;Actor&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;?php
    foreach ($elementi as $key =&gt; $value) {
        echo $value-&gt;actor_id;
        echo $value-&gt;fullname; 
        echo $value-&gt;last_update;
    }
    
    ?&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p dir="auto">l'errore che mi restituisce è questo:</p>
<p dir="auto"><strong>A PHP Error was encountered</strong><br />
<strong>Severity: Notice</strong><br />
<strong>Message: Undefined property: actor::$db</strong><br />
<strong>Filename: core/Model.php</strong><br />
<strong>Line Number: 52</strong></p>
<p dir="auto">grazie 1000 in anticipo<br />
buona serata a tutti</p>
]]></description><link>https://dev.connect.gt/post/1189159</link><guid isPermaLink="true">https://dev.connect.gt/post/1189159</guid><dc:creator><![CDATA[enricocarli]]></dc:creator><pubDate>Wed, 18 Feb 2015 18:38:05 GMT</pubDate></item><item><title><![CDATA[Reply to framework on Sat, 14 Feb 2015 22:08:42 GMT]]></title><description><![CDATA[<p dir="auto">Ciao,<br />
le basi le trovi anche qui, anche se per questioni di tempo non ho potuto finire la guida:<br />
<a href="http://www.giorgiotave.it/forum/scripting-e-risorse-utili/198679-guida-codeigniter.html" rel="nofollow ugc">http://www.giorgiotave.it/forum/scripting-e-risorse-utili/198679-guida-codeigniter.html</a></p>
]]></description><link>https://dev.connect.gt/post/1189155</link><guid isPermaLink="true">https://dev.connect.gt/post/1189155</guid><dc:creator><![CDATA[thedarkita]]></dc:creator><pubDate>Sat, 14 Feb 2015 22:08:42 GMT</pubDate></item><item><title><![CDATA[Reply to framework on Sat, 14 Feb 2015 13:45:45 GMT]]></title><description><![CDATA[<p dir="auto">Ciao Enrico,</p>
<p dir="auto">Benvenuto nel forum! <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=12b9555a9a1" class="not-responsive emoji emoji-android emoji--smile" style="height:1.4em;width:auto;vertical-align:middle" title=":D" alt="😄" /></p>
<p dir="auto">Parto dal presupposto che tu abbia esperienza con PHP, SQL (e la sua implementazione in MySQL) e l'utilizzo "object oriented" di PHP. Nel caso così non fosse, ti <a href="http://www.tizag.com/phpT/" rel="nofollow ugc"><strong>consiglio di rimediare</strong></a> prima di procedere con CodeIgniter o altri framework.</p>
<p dir="auto">Puoi immaginare un framework come un pacchetto di funzioni che facilitano lo sviluppo di applicazioni web. Nello specifico:</p>
<ul>
<li>Evitano di dover "reinventare la ruota" riscrivendo ogni volta funzioni per collegarsi al database, acquisire dati passati tramite GET/POST, URL Rewrite etc;</li>
<li>Strutturano l'applicazione in diversi "moduli" (appunto, "Views", "Models" e "Controllers", l'architettura MVC) che facilita la futura espansione del progetto e garantisce una distribuzione delle risorse sensata.</li>
</ul>
<p dir="auto"><em><strong>Partiamo da un discorso generale, prima di entrare nei dettagli di CodeIgniter...</strong></em></p>
<p dir="auto">L'architettura MVC non è legata ad un particolare linguaggio. Per quanto CodeIgniter sia scritto in PHP (come altri quali Laraverl e CakePHP) ne esistono altrettanti non basati su tale linguaggio, quale il framework "rails" per Ruby (Ruby on Rails).</p>
<p dir="auto">Un'applicazione MVC è composta da tre unità fondamentali:</p>
<ul>
<li>"<strong>Views</strong>": File semi-statici che hanno il solo compito di disporre il contenuto sulla pagina. Solitamente si tratta di un misto di HTML, CSS e Javascript (ed estensioni varie quali JQuery, AJAX, etc.)</li>
</ul>
<pre><code>&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;Nome:&lt;/td&gt;&lt;td&gt;$utente-&gt;nome&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cognome&lt;/td&gt;&lt;td&gt;$utente-&gt;cognome&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt; Data Registratione&lt;/td&gt;&lt;td&gt;$utente-&gt;data_registratione&lt;/td&gt;
&lt;/tr&gt;
</code></pre>
<ul>
<li>"<strong>Contollers</strong>": Lo "scheletro" dell'applicazione. Questo è il file che viene chiamato quando l'utente invia una richiesta al server. Ad esempio, se la tua applicazione risiede su <em><a href="http://example.com" rel="nofollow ugc">example.com</a></em>, una richiesta a <em><a href="http://example.com/user" rel="nofollow ugc">example.com/user</a></em> sara indirizzata al <em>controller</em> "Users". Ad esempio:</li>
</ul>
<pre><code>// Questa classe estende la classe 'controller' del framework
class users extends controller {

// Qui possiamo eseguire delle istrizioni ogni volta che il controller
// viene chiamato indipendentemente da quale richiesta sarà poi eseguita
function __construct() {

// Necessario in CI
parent::__construct();

}

function index() {

/* Codice */

}

function add() 

/* Codice */

}

function delete($id) {

/* Codice */

}
</code></pre>
<p dir="auto">Ritornando quindi al nostro esempio <em><a href="http://example.com/users" rel="nofollow ugc">example.com/users</a>"</em>. "users" è il primo "url  segment", ovvero dice al framework di indirizzare la richiesta al controller "users". Per default, la funzione chiamata è "index". Tuttavia, possiamo decidere altrimenti specificando un secondo "url segment". Ad esempio, <em><a href="http://example.com/users/add" rel="nofollow ugc">example.com/users/add</a></em> eseguirà la funzione "add" del controller "users". Infine, il terzo "url segment" rappresenta un parametro passato alla funzione. <em><a href="http://example.com/users/delete" rel="nofollow ugc">example.com/users/delete</a></em> chiamerà la funzione 'delete' assegnando $id = 3. Alcuni framework, fra cui CodeIgniter, permettono di dichiarare ulteriori url fragment.</p>
<p dir="auto">Le "views" sono chiamate dal "controller". Ad esempio:</p>
<pre><code>function index() {

$this-&gt;load-&gt;view('index');

}
</code></pre>
<p dir="auto">Eseguirà il file index.php nella cartella 'views' e trasmetterà il risultato (html) al browser.</p>
<p dir="auto">Possiamo anche caricare più "views" che verranno caricate nell'ordine.</p>
<pre><code>function index() {

$this-&gt;load-&gt;view('header');
$this-&gt;load-&gt;view('index');
$thsi-&gt;load-&gt;view('footer');

}
</code></pre>
<ul>
<li>Infine, i "<strong>model</strong>" si occupano di rappresentare il database. In genere si ha un model per tabella, anche se ciò può variare a seconda dei casi. I model sono responsabili per interagire direttamente e aggiornare o caricare informazioni salvate sul DB. Solitamente un model può: Ricevere un oggetto e salvarlo sul database <em>o</em> ricevere informazione dal database e passarla come oggetto al controller. Ad esempio:</li>
</ul>
<pre><code>class users_model extends model {

// Inserisce l'oggetto nel DB
function insert($user) {

$sql = "INSERT INTO users (nome, cognome, eta) VALUES ($user-&gt;nome, $user-&gt;cognome, $user-&gt;età)";
$this-&gt;query($sql);

}

function get($id) {

$sql = "SELECT users.nome, users.cognome, users.eta FROM users WHERE id = $id";
$result = $this-&gt;query($sql);

$user = new user();
$user-&gt;nome = $result-&gt;nome;
$user-&gt;cognome = $result-&gt;cognome;
$user-&gt;eta = $result-&gt;eta;

return $user;

}

}
</code></pre>
<p dir="auto">Quindi, la richiesta viene inoltrata al <strong>controller</strong> , il <strong>controller</strong> elabora la richiesta, aggiorna il database o recupera informazioni tramite il <strong>model</strong> e la trasmette al <strong>view</strong> che la presenta all'utente.</p>
<p dir="auto"><em><strong>Per quanto riguarda CodeIgniter</strong></em></p>
<p dir="auto">CI usa la propria library 'load' per generare istanze di un oggetto.</p>
<p dir="auto">Quindi, invece di:</p>
<pre><code class="language-php">include('../models/myModel.php');
</code></pre>
<p dir="auto">Si usa:</p>
<pre><code class="language-php">$this-&gt;load-&gt;model('myModel');
</code></pre>
<p dir="auto">Che si può poi chiamare tramite</p>
<pre><code class="language-php"> $this-&gt;myModel-&gt;myMethod();
</code></pre>
<p dir="auto">Ad esempio:</p>
<pre><code class="language-php">$user = $this-&gt;myModel-&gt;getWhereId($id);
</code></pre>
<p dir="auto">Può essere usato per recuperare un oggetto 'user' dal database.</p>
<p dir="auto">Per le views:</p>
<pre><code class="language-php">$this-&gt;load-&gt;view('view');
</code></pre>
<p dir="auto">Genera il file view.php nella cartella views.</p>
<p dir="auto"><em><strong>Fammi sapere come va! <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=12b9555a9a1" class="not-responsive emoji emoji-android emoji--smile" style="height:1.4em;width:auto;vertical-align:middle" title=":D" alt="😄" /></strong></em></p>
]]></description><link>https://dev.connect.gt/post/1189161</link><guid isPermaLink="true">https://dev.connect.gt/post/1189161</guid><dc:creator><![CDATA[max0005]]></dc:creator><pubDate>Sat, 14 Feb 2015 13:45:45 GMT</pubDate></item></channel></rss>