Guest User

Untitled

a guest
Aug 8th, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. <?php
  2. class PostsController extends AppController{
  3.  
  4.     public $helpers = array('Date');
  5.     public $components = array('RequestHandler');
  6.     public $cacheAction = array(
  7.         'index' => '2 DAY',
  8.         'show' => '2 DAY'
  9.     );
  10.     public $paginate = array(
  11.         'limit' => 2,
  12.         'order' => array(
  13.             'Post.title' => 'asc'
  14.         )
  15.     );
  16.  
  17.     function index(){
  18.         $d['posts'] = $this->paginate('Post');
  19.         $this->set($d);
  20.     }
  21.  
  22.    
  23.     function category($category){
  24.         $cat = $this->Post->Category->find('first',array(
  25.             'conditions' => array('slug' => $category)
  26.         ));
  27.         if(empty($cat))
  28.             throw new NotFoundException('Aucune catégorie ne correspond à ce nom');
  29.         $d['posts'] = $this->Paginate('Post',array('type'=>'post','online'=>1,'category_id' => $cat['Category']['id']));
  30.         $d['title'] = 'Tous les articles "'.$cat['Category']['name'].'"';
  31.         $this->set($d);
  32.         $this->render('index');
  33.     }
  34.  
  35.     function show($id = null,$slug = null){
  36.         if(!$id)
  37.             throw new NotFoundException('Aucune page ne correspond à cet ID');
  38.         $post = $this->Post->find('first',array(
  39.             'conditions' => array('Post.id' => $id),
  40.             'recursive'  => 0
  41.         ));
  42.         if(empty($post))
  43.             throw new NotFoundException('Aucune page ne correspond à cet ID');
  44.         if($slug != $post['Post']['slug'])
  45.             $this->redirect($post['Post']['link'],301);
  46.         $d['post'] = $post;
  47.         $this->set($d);
  48.     }
  49.  
  50.  
  51.     function feed(){
  52.         if ($this->RequestHandler->isRss() ){
  53.             $d['posts'] = $this->Post->find('all', array(
  54.                 'limit' => 10,
  55.                 'conditions' => array('type'=>'post')
  56.              ));
  57.             return $this->set($d);
  58.         }
  59.     }
  60.  
  61.     function admin_index(){
  62.         $d['posts'] = $this->Paginate('Post',array('type'=>'post','online >= 0'));
  63.         $this->set($d);
  64.     }
  65.     function admin_edit($id = null){
  66.         if($this->request->is('put') || $this->request->is('post')){
  67.             if($this->Post->save($this->request->data)){
  68.                 $this->Session->setFlash("Le contenu a bien été modifié","notif");
  69.                 $this->redirect(array('action'=>'index'));
  70.             }
  71.         }elseif($id){
  72.             $this->Post->id = $id;
  73.             $this->request->data = $this->Post->read();
  74.         }else{
  75.             $this->request->data = $this->Post->getDraft('post');
  76.         }
  77.         $d['categories'] = $this->Post->Category->find('list');
  78.         $this->set($d);
  79.     }
  80.     function admin_delete($id){
  81.         $this->Session->setFlash('L\'article a bien été supprimé a bien été supprimée','notif');
  82.         $this->Post->delete($id);
  83.         $this->redirect($this->referer());
  84.     }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment