<?php
class PostsController extends Controller{
function index(){
$perPage=1;
$this->loadModel('Post');
$condition=array('online'=>'1','type'=>'post');
$d'posts']=$this->Post->find(array(
'conditions'=>$condition,
'limit'=>($perPage*$this->request->page=1).','.$perPage
));
$d'total']=$this->Post->findCount($condition);
$d'page']=ceil($d'total'] /$perPage);
$this->set($d);
}
function view($id,$slug){
$this->loadModel('Post');
$condition=array('online'=>'1','id'=>$id,'type'=>'post');
$d'post']=$this->Post->findFirst(array(
'fields'=>'id,slug,content,name',
'conditions'=>$condition));
if(empty($d'post'])){
$this->e404('Page Introvable');
}
//if ($slug!=$d'post']->slug) {
//$this->redirect("posts/view/id:$id/slug:".$d'post']->slug,'301');
//}
$this->set($d);
}
/**
**admin
*/
function admin_index(){
$perPage=10;
$this->loadModel('Post');
$condition=array('type'=>'post');
$d'posts']=$this->Post->find(array(
'fields'=>'id,name,online',
'conditions'=>$condition,
'limit'=>($perPage*$this->request->page=1).','.$perPage
));
$d'total']=$this->Post->findCount($condition);
$d'page']=ceil($d'total'] /$perPage);
$this->set($d);
}
//Permet de suprimer un article
function admin_delete($id){
$this->loadModel('Post');
$this->Post->delete($id);
$this->redirect('admin/posts/index');
}
}
?>