gnopaste

Sorry for this ugly message. We are searching for some translators.
Please send me an eMail or jabber: t4c@im.digital-bit.ch
Got: de, en, pl, ro, lu, ru, es - Need: everything else

Name
ex1t
Scriptlanguage
PHP
Tabwidth
2
Date
06/30/2009 01:07:33 pm
IP
92.229.121.141

The user was too lazy to give a description

  1. <?php
  2. class NewsController extends AppController {
  3.   var $name = 'News';
  4.   
  5.   /* Hauptausgabe */
  6.   function index() {
  7.     /* News aus der Datenbank raussuchen */
  8.     $news = $this -> News -> find('all', array(
  9.                           'order' => 'id',
  10.                           'direction' => 'desc',
  11.                           'limit' => '10'
  12.                            ));
  13.     /* Inhalt in die Templatevariable news übergeben */
  14.     $this -> set('news', $news);
  15.   }
  16.   /* Ausgabe der News nach ID sowie der Kommentare */
  17.   function comments($id) {
  18.     /* News von der entsprechenden ID selecten */
  19.     $news = $this -> News -> read(null, $id);
  20.     
  21.     /* Ist der Newsartikel überhaupt vorhanden? Wenn nicht -> bam back zum index.. */
  22.     if (empty($news['news']['id'])) {
  23.       $this->Session->setFlash('Der von dir angeforderte Newsartikel scheint nicht vorhanden zu sein.');
  24.       $this->redirect(array('action'=>'index'));
  25.     }
  26.     /* Kommentare zählen */
  27.     $cmtcount = $this -> News -> Comments -> find('count', array('conditions' => array('Comments.news_id' => ''.$id.'')));
  28.     /* Kommentare auswählen */
  29.     $comments = $this -> News -> Comments -> find('all', array(
  30.                                     'order' => 'id',
  31.                                     'direction' => 'desc'
  32.                                   'conditions' => array('Comments.news_id' => ''.$id.''
  33.                                      )));
  34.     /* Sind überhaupt Kommentare vorhanden? */
  35.     if($cmtcount == "0") { $nocmt = true; } else { $nocmt = false; }
  36.       
  37.     /* Abgeschickten Kommentar in die Datenbank eintragen - und einige Checks bzw. Fehlermeldungen */
  38.     if(!empty($this -> data)) {
  39.       if(empty($this->data['Comments']['content'])) {
  40.         $this -> Session -> setFlash('Das Feld Kommentartext darf nicht leer sein.');
  41.       } else {
  42.       $this -> data ['Comments']['content'] = Sanitize::html($this->data['Comments']['content']);  
  43.       $this->data = Sanitize::clean($this->data, array('encode' => false));
  44.       $this->data['Comments']['news_id'] = $id;
  45.       $this -> News -> Comments -> create();
  46.       if($this -> News -> Comments -> save($this->data)) {
  47.         $this -> Session -> setFlash('Dein Kommentar wurde eingetragen.');
  48.         $this -> redirect('/news/comments/'.$id.'');
  49.       } else {
  50.         $this -> Session -> setFlash('Leider ist beim eintragen ein Fehler aufgetreten. Bitte versuche es erneut.');
  51.       }
  52.       }
  53.     }
  54. }
  55. }
  56. ?>
submitter » gnopaster | imprint « imprint     
» Terms of use «
» digital bit dot ch - t4c's new home «