Exemple #1
0
 public function view($id)
 {
     $this->Book->recursive = 1;
     // Si le livre recherché n'existe pas
     if (!($book = $this->Book->findById($id))) {
         $this->Session->setFlash(__('Le livre que vous recherchez n\'existe pas.'), 'admin_error');
         $this->redirect($this->referer());
     }
     // Partie pour récupérer la note moyenne du livre afin d'afficher les étoiles
     $starNumber = 0;
     foreach ($book['Comment'] as $k => $v) {
         $starNumber += $v['rating'];
     }
     if (count($book['Comment']) != 0) {
         $starNumber = $starNumber / count($book['Comment']);
     } else {
         $starNumber = 0;
     }
     $this->set('starNumber', $starNumber);
     $Comment = new CommentsController();
     // On instancie l'objet CommentsController
     $book = $Comment->view($id);
     // On appel la fonction souhaité
     $this->set('book', $book);
 }
Exemple #2
0
<?php

class CommentsController extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->setModel('Comments');
    }
}
$controller = new CommentsController();
$controller->view(ADMIN_TPLS_DIR . '/header.tpl');
$controller->view(ADMIN_TPLS_DIR . '/comments.tpl');
$controller->view(ADMIN_TPLS_DIR . '/footer.tpl');