1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| <?php
App::uses('AppController', 'Controller');
/**
* Static content controller
*
* Override this controller by placing a copy in controllers directory of an application
*
* @package app.Controller
* @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
*/
class PagesController extends AppController {
/**
* Controller name
*
* @var string
*/
public $name = 'Pages';
/**
* Default helper
*
* @var array
*/
public $helpers = array('Html', 'Session');
/**
* This controller does not use a model
*
* @var array
*/
public $uses = array('Post');
/**
* Displays a view
*
* @param mixed What page to display
* @return void
*/
public function display() {
$path = func_get_args();
$count = count($path);
if (!$count) {
$this->redirect('/');
}
$page = $subpage = $title_for_layout = null;
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
if (!empty($path[$count - 1])) {
$title_for_layout = Inflector::humanize($path[$count - 1]);
}
$this->set(compact('page', 'subpage', 'title_for_layout'));
$this->render(implode('/', $path));
}
function menu(){
$pages = $this->Post->find('all',array(
'conditions' => array('type' =>'page', 'online'=>1),
'fields' =>array('id','slug','name')
));
return $pages;
}
function show($id = null, $slug = null){
if(!$id)
throw new NotFoundException('Aucune page ne correspond a cet ID');
$page = $this->Post->find('first',array(
'conditions' => array('id' => $id)
));
if(empty($page))
throw new NotFoundException('Aucune page ne correspond a cet ID');
if($slug != $page['Post']['slug'])
$this->redirect($page['Post']['link'],301);
$d['page'] = current($page);
$this->set($d);
}
/**
* parie avec les prefix
**/
function admin_index(){
$d['pages'] = $this->Paginate('Post',array('type'=>'page'));
$this->set($d);
}
} |
Partager