--- /dev/null
+<?php
+ class ProductsController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+
+ // GETTING ALL PRODUCTS
+ $products = $this->Product->find('all');
+
+ // GETTING VERSION CONTROLLER AND ALL VERSIONS
+ App::import('Controller', 'Versions');
+ $versionsController = new VersionsController;
+ $versions = $versionsController->Version->find('all');
+
+ // SENDING DATA TO VIEW
+ $this->set(array(
+ 'products' => $products,
+ '_serialize' => array('products')
+ ));
+ $this->set(array(
+ 'versions' => $versions,
+ '_serialize' => array('versions')
+ ));
+ }
+
+ public function add() {
+ if ($this->request->is('POST')) {
+ $this->Product->create();
+ if ($this->Product->save($this->request->data)) {
+ $this->Session->setFlash(__("Le produit a été enregistré."));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Enregistrement du produit impossible."));
+ }
+ }
+
+ public function edit($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Produit introuvable'));
+ }
+
+ $product = $this->Product->findById($id);
+ if (!$product) {
+ throw new NotFoundException(__('Produit introuvable'));
+ }
+
+ if ($this->request->is(array('product', 'put'))) {
+ $this->Product->id = $id;
+ if ($this->Product->save($this->request->data)) {
+ $this->Session->setFlash(__("La produit a été mis à jour."));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour du produit impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $product;
+ }
+ }
+
+ public function delete($id) {
+ if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }
+
+ if ($this->Product->delete($id)) {
+ $this->Session->setFlash(
+ __("La produit d'id: %s a été supprimé.", h($id))
+ );
+ $this->redirect(array('action' => 'index'));
+ }
+ }
+ }
+?>