Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- App::uses('AppController', 'Controller');
- /**
- * Comments Controller
- *
- * @property Comment $Comment
- */
- class CommentsController extends AppController {
- /**
- * Ajout de commentaire.
- **/
- public function add($guestbook_id = null){
- if(!$guestbook_id && !$this->request->is('post'))
- throw new NotFoundException('Aucun message ne correspond à cet ID');
- if($this->request->is('post')){
- $last = $this->Comment->find('first',array(
- 'conditions'=>array('guestbook_id' => $guestbook_id),
- 'order' => 'created desc',
- 'recursive' => -1
- ));
- if($last['Comment']['clientip'] == $_SERVER['REMOTE_ADDR']){
- $this->Session->setFlash("Vous ne pouvez pas poster 2 commentaires à la suite, veuillez attendre que quelqu'un post un commentaire","notif",array('type'=>'error'));
- $this->redirect($this->referer());
- } else {
- $d = $this->request->data;
- $d['Comment']['clientip'] = $_SERVER['REMOTE_ADDR'];
- if($this->Comment->save($d,true,array('name','email','content','clientip','guestbook_id'))){
- $this->Session->setFlash("Votre commentaire à bien été envoyé","notif");
- $this->redirect($this->referer());
- } else {
- $this->Session->setFlash("Votre commentaire n'a pas pu être enregistré, veuillez réessayé","notif",array('type'=>'error'));
- $this->redirect($this->referer());
- }
- }
- } else {
- $d['guestbook_id'] = $guestbook_id;
- $this->set($d);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment