public $components = array('RequestHandler');
public function index() {
- //$this->set('produits', $this->Produit->find('all'));
+ // RÉCUPÉRATION DES PRODUITS
$produits = $this->Produit->find('all');
+
+ // To-do : Récupérer versions de chaque produit
+
+ // ENVOI DES DONNÉES À LA VUE
$this->set(array(
'produits' => $produits,
'_serialize' => array('produits')
}
public function add() {
- if ($this->request->is('produit')) {
+ if ($this->request->is('POST')) {
$this->Produit->create();
if ($this->Produit->save($this->request->data)) {
- $this->Session->setFlash(__('Le produit a été enregistré.'));
+ $this->Session->setFlash(__("Le produit a été enregistré."));
return $this->redirect(array('action' => 'index'));
}
- $this->Session->setFlash(__('Enregistrement du produit impossible.'));
+ $this->Session->setFlash(__("Enregistrement du produit impossible."));
}
}
if ($this->request->is(array('produit', 'put'))) {
$this->Produit->id = $id;
if ($this->Produit->save($this->request->data)) {
- $this->Session->setFlash(__('Le produit a été mis à jour.'));
+ $this->Session->setFlash(__("La produit a été mis à jour."));
return $this->redirect(array('action' => 'index'));
}
- $this->Session->setFlash(__('Mise à jour du produit impossible.'));
+ $this->Session->setFlash(__("Mise à jour du produit impossible."));
}
if (!$this->request->data) {
if ($this->Produit->delete($id)) {
$this->Session->setFlash(
- __("Le produit d'id: %s a été supprimé.", h($id))
+ __("La produit d'id: %s a été supprimé.", h($id))
);
return $this->redirect(array('action' => 'index'));
}
}
-
- // API REST
-
- /*public function rest_get_all() {
- $produits = $this->Produit->find('all');
- $this->set(array(
- 'produits' => $produits,
- '_serialize' => array('produits')
- ));
- }
-
- public function rest_get($reference) {
- $produit = $this->Produit->findByReference($reference);
- $this->set(array(
- 'produit' => $produit,
- '_serialize' => array('produit')
- ));
- }
-
- public function rest_create() {
- if ($this->Produit->save($this->request->data)) {
- $message = array(
- 'text' => __('Saved'),
- 'type' => 'success'
- );
- } else {
- $message = array(
- 'text' => __('Error'),
- 'type' => 'error'
- );
- }
- $this->set(array(
- 'message' => $message,
- '_serialize' => array('message')
- ));
- }
-
- public function rest_update($reference) {
- $this->Produit->reference = $reference;
- if ($this->Produit->save($this->request->data)) {
- $message = array(
- 'text' => __('Saved'),
- 'type' => 'success'
- );
- } else {
- $message = array(
- 'text' => __('Error'),
- 'type' => 'error'
- );
- }
- $this->set(array(
- 'message' => $message,
- '_serialize' => array('message')
- ));
- }
-
- public function rest_delete($reference) {
- if ($this->Produit->delete($reference)) {
- $message = array(
- 'text' => __('Deleted'),
- 'type' => 'success'
- );
- } else {
- $message = array(
- 'text' => __('Error'),
- 'type' => 'error'
- );
- }
- $this->set(array(
- 'message' => $message,
- '_serialize' => array('message')
- ));
- }*/
}
?>