Ti trovi su Risorse Webmaster > Creiamo il nostro blog con CodeIgniter
Creiamo il nostro blog con CodeIgniter
La visualizzazione dei dati
Ora passiamo alla parte relative alle viste che vengono richiamate dal Blog controller, utilizzando i dati forniti dal modello attraverso l''interrogazioni al database. Questi file devono essere salvati nella cartella system/application/views/.
index.php
- <html>
- <head>
- <title><?= $title; ?></title>
- </head>
- <body>
- <h1><?= $heading; ?></h1>
- <?php
- if (user[''loggato''] === TRUE) {
- echo anchor(''utenti/logout'', ''Logout'');
- echo ''<br />'';
- echo anchor(''blog/ins'', ''Scrivi un post'');
- } else {
- echo anchor(''utenti/login'', ''Login'');
- echo " ";
- echo anchor(''utenti/registra'', ''Registrati);
- }
- ?>
- <p></p>
- <?php
- if (isset($articoli)) {
- foreach ($articoli as $id=>$art) {
- echo "<h2>".$art[''art_titolo'']."</h2>";
- echo $art[''art_articolo''];
- echo "<br /><br />";
- echo "Scritto da <strong>".$art[''art_autore'']."</strong>";
- echo " | Articolo postato il <strong>".preg_replace(''/^(.{4})-(.{2})-(.{2})$/'', ''$3-$2-$1'', $art[''art_data'']);
- </body>
- </html>
ins.php
- <html>
- <head>
- <title>Il mio Blog: inserimento articolo</title>
- </head>
- <body>
- <h1>Inserisci un articolo</h1>
- <?= form_open(''blog/ins''); ?>
- <p><label for="autore">Autore</label><br />
- <input type="text" name="autore" id="autore" size="50" /></p>
- <p><label for="titolo">Titolo</label><br />
- <input type="text" name="titolo" id="titolo" size="50" /></p>
- <p><label for="testo">Testo:</label><br />
- <textarea name="testo" id="testo" rows="10" cols="60"></textarea></p>
- <p><input type="submit" value="articolo" /></p>
- <?= form_close(); ?>
- </body>
- </html>
articolo.php
- <html>
- <head>
- <title>Il mio Blog</title>
- </head>
- <body>
- <h2><?= $articolo[''art_titolo'']; ?></h2>
- <?= $articolo[''art_articolo'']; ?><br /><br />
- Scritto da <strong><?= $articolo[''art_autore'']; ?></strong>
- | Articolo postato il <?= preg_replace(''/^(.{4})-(.{2})-(.{2})$/'', ''$3-$2-1'', $articolo[''art_data'']);
- <p><?= anchor(''blog''commenti''.$articolo[''art_id''], ''Commenti''); ?></p>
- </body>
- </html>
commenti.php
- <html>
- <head>
- <title>Il mio Blog: Commenti</title>
- </head>
- <body>
- <?php if ($query->num_rows() > 0) { ?>
- <?php foreach($query->result() as $row) { ?>
- <h3><?= $row->com_autore; ?></h3>
- <p><?= $row->com_testo; ?></p>
- <hr />
- <?php } ?>
- <?php } ?>
- <?= anchor(''blog'', ''Torna al blog''); ?>
- <?= form_open(''blog/ins_commenti''); ?>
- <?= form_hiddden(''com_id'', $this->uri->segment(3)); ?>
- <p><label for="autore">Autore:</label><br />
- <input type="text" name="com_autore" id="com_autore" /></p>
- <p><label for="testo">Testo:</label><br />
- <textarea name="com_testo" id="com_testo" rows=24" cols="30"></textarea></p>
- <p><input type="submit" value="Commento" /></p>
- <?= form_close(); ?>
- </body>
- </html>
Conclusioni
Il nostro blog, estremamente essenziale, non è anchora termitato. Nel prossimo articolo ci occuperemo della gestione degli utenti.


