Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class PostsController extends AppController{
- public $helpers = array('Date');
- public $components = array('RequestHandler');
- public $cacheAction = array(
- 'index' => '2 DAY',
- 'show' => '2 DAY'
- );
- public $paginate = array(
- 'limit' => 2,
- 'order' => array(
- 'Post.title' => 'asc'
- )
- );
- function index(){
- $d['posts'] = $this->paginate('Post');
- $this->set($d);
- }
- function category($category){
- $cat = $this->Post->Category->find('first',array(
- 'conditions' => array('slug' => $category)
- ));
- if(empty($cat))
- throw new NotFoundException('Aucune catégorie ne correspond à ce nom');
- $d['posts'] = $this->Paginate('Post',array('type'=>'post','online'=>1,'category_id' => $cat['Category']['id']));
- $d['title'] = 'Tous les articles "'.$cat['Category']['name'].'"';
- $this->set($d);
- $this->render('index');
- }
- function show($id = null,$slug = null){
- if(!$id)
- throw new NotFoundException('Aucune page ne correspond à cet ID');
- $post = $this->Post->find('first',array(
- 'conditions' => array('Post.id' => $id),
- 'recursive' => 0
- ));
- if(empty($post))
- throw new NotFoundException('Aucune page ne correspond à cet ID');
- if($slug != $post['Post']['slug'])
- $this->redirect($post['Post']['link'],301);
- $d['post'] = $post;
- $this->set($d);
- }
- function feed(){
- if ($this->RequestHandler->isRss() ){
- $d['posts'] = $this->Post->find('all', array(
- 'limit' => 10,
- 'conditions' => array('type'=>'post')
- ));
- return $this->set($d);
- }
- }
- function admin_index(){
- $d['posts'] = $this->Paginate('Post',array('type'=>'post','online >= 0'));
- $this->set($d);
- }
- function admin_edit($id = null){
- if($this->request->is('put') || $this->request->is('post')){
- if($this->Post->save($this->request->data)){
- $this->Session->setFlash("Le contenu a bien été modifié","notif");
- $this->redirect(array('action'=>'index'));
- }
- }elseif($id){
- $this->Post->id = $id;
- $this->request->data = $this->Post->read();
- }else{
- $this->request->data = $this->Post->getDraft('post');
- }
- $d['categories'] = $this->Post->Category->find('list');
- $this->set($d);
- }
- function admin_delete($id){
- $this->Session->setFlash('L\'article a bien été supprimé a bien été supprimée','notif');
- $this->Post->delete($id);
- $this->redirect($this->referer());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment