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

  1.  <html>
  2.  <head>
  3.  <title><?= $title; ?></title>
  4.  </head>
  5.  <body>
  6.  <h1><?= $heading; ?></h1>
  7.  <?php
  8.  if (user[''loggato''] === TRUE) {
  9.    echo anchor(''utenti/logout'', ''Logout'');
  10.    echo ''<br />'';
  11.    echo anchor(''blog/ins'', ''Scrivi un post'');
  12.  } else {
  13.    echo anchor(''utenti/login'', ''Login'');
  14.    echo " ";
  15.    echo anchor(''utenti/registra'', ''Registrati);
  16.  }
  17.  ?>
  18.  <p></p>
  19.  <?php
  20.  if (isset($articoli)) {
  21.    foreach ($articoli as $id=>$art) {
  22.       echo "<h2>".$art[''art_titolo'']."</h2>";
  23.       echo $art[''art_articolo''];
  24.       echo "<br /><br />";
  25.       echo "Scritto da <strong>".$art[''art_autore'']."</strong>";
  26.       echo " | Articolo postato il <strong>".preg_replace(''/^(.{4})-(.{2})-(.{2})$/'', ''$3-$2-$1'', $art[''art_data'']);
  27.  </body>
  28.  </html>

ins.php

  1. <html>
  2.  <head>
  3.  <title>Il mio Blog: inserimento articolo</title>
  4.  </head>
  5.  <body>
  6.  <h1>Inserisci un articolo</h1>
  7.  <?= form_open(''blog/ins''); ?>
  8. <p><label for="autore">Autore</label><br />
  9.  <input type="text" name="autore" id="autore" size="50" /></p>
  10.  <p><label for="titolo">Titolo</label><br />
  11.  <input type="text" name="titolo" id="titolo" size="50" /></p>
  12.  <p><label for="testo">Testo:</label><br />
  13.  <textarea name="testo" id="testo" rows="10" cols="60"></textarea></p>
  14.  <p><input type="submit" value="articolo" /></p>
  15.  <?= form_close(); ?>
  16.  </body>
  17.  </html>

articolo.php

  1.  <html>
  2.  <head>
  3.  <title>Il mio Blog</title>
  4.  </head>
  5.  <body>
  6.  <h2><?= $articolo[''art_titolo'']; ?></h2>
  7.  <?= $articolo[''art_articolo'']; ?><br /><br />
  8.  Scritto da <strong><?= $articolo[''art_autore'']; ?></strong>
  9.  | Articolo postato il <?= preg_replace(''/^(.{4})-(.{2})-(.{2})$/'', ''$3-$2-1'', $articolo[''art_data'']);
  10.  <p><?= anchor(''blog''commenti''.$articolo[''art_id''], ''Commenti''); ?></p>
  11.  </body>
  12.  </html>

commenti.php

  1.  <html>
  2.  <head>
  3.  <title>Il mio Blog: Commenti</title>
  4.  </head>
  5.  <body>
  6.  <?php if ($query->num_rows() > 0) { ?>
  7.  <?php foreach($query->result() as $row) { ?>
  8.  <h3><?= $row->com_autore; ?></h3>
  9.  <p><?= $row->com_testo; ?></p>
  10.  <hr />
  11.  <?php } ?>
  12.  <?php } ?>
  13.  <?= anchor(''blog'', ''Torna al blog''); ?>
  14.  <?= form_open(''blog/ins_commenti''); ?>
  15.  <?= form_hiddden(''com_id'', $this->uri->segment(3)); ?>
  16.  <p><label for="autore">Autore:</label><br />
  17.  <input type="text" name="com_autore" id="com_autore" /></p>
  18.  <p><label for="testo">Testo:</label><br />
  19.  <textarea name="com_testo" id="com_testo" rows=24" cols="30"></textarea></p>
  20.  <p><input type="submit" value="Commento" /></p>
  21.  <?= form_close(); ?>
  22.  </body>
  23.  </html>

Conclusioni

Il nostro blog, estremamente essenziale, non è anchora termitato. Nel prossimo articolo ci occuperemo della gestione degli utenti.

 
© Computer Flash | |