+++ /dev/null
-<?php
- class ProduitsController extends AppController {
- public $helpers = array('Html', 'Form');
- public $components = array('RequestHandler');
-
- public function index() {
- // GETTING ALL PRODUCTS
- $produits = $this->Produit->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(
- 'produits' => $produits,
- '_serialize' => array('produits')
- ));
- $this->set(array(
- 'versions' => $versions,
- '_serialize' => array('versions')
- ));
- }
-
- public function view($id = null) {
- if (!$id) {
- throw new NotFoundException(__('Mauvais produit'));
- }
-
- $produit = $this->Produit->findById($id);
- if (!$produit) {
- throw new NotFoundException(__('Mauvais produit'));
- }
- $this->set('produit', $produit);
- }
-
- public function add() {
- if ($this->request->is('POST')) {
- $this->Produit->create();
- if ($this->Produit->save($this->request->data)) {
- $this->Session->setFlash(__("Le produit a été enregistré."));
- return $this->redirect(array('action' => 'index'));
- }
- $this->Session->setFlash(__("Enregistrement du produit impossible."));
- }
- }
-
- public function edit($id = null) {
- if (!$id) {
- throw new NotFoundException(__('Produit introuvable'));
- }
-
- $produit = $this->Produit->findById($id);
- if (!$produit) {
- throw new NotFoundException(__('Produit introuvable'));
- }
-
- if ($this->request->is(array('produit', 'put'))) {
- $this->Produit->id = $id;
- if ($this->Produit->save($this->request->data)) {
- $this->Session->setFlash(__("La produit a été mis à jour."));
- return $this->redirect(array('action' => 'index'));
- }
- $this->Session->setFlash(__("Mise à jour du produit impossible."));
- }
-
- if (!$this->request->data) {
- $this->request->data = $produit;
- }
- }
-
- public function delete($id) {
- if ($this->request->is('get')) {
- throw new MethodNotAllowedException();
- }
-
- if ($this->Produit->delete($id)) {
- $this->Session->setFlash(
- __("La produit d'id: %s a été supprimé.", h($id))
- );
- return $this->redirect(array('action' => 'index'));
- }
- }
- }
-?>