68 lines
1.8 KiB
PHP
68 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
class ProductsController extends AppController {
|
||
|
|
|
||
|
|
var $name = 'Products';
|
||
|
|
var $helpers = array('Html', 'Form');
|
||
|
|
|
||
|
|
function index() {
|
||
|
|
$this->Product->recursive = 0;
|
||
|
|
$this->set('products', $this->paginate());
|
||
|
|
}
|
||
|
|
|
||
|
|
function view($id = null) {
|
||
|
|
if (!$id) {
|
||
|
|
$this->Session->setFlash(__('Invalid Product.', true));
|
||
|
|
$this->redirect(array('action'=>'index'));
|
||
|
|
}
|
||
|
|
$this->set('product', $this->Product->read(null, $id));
|
||
|
|
}
|
||
|
|
|
||
|
|
function add() {
|
||
|
|
if (!empty($this->data)) {
|
||
|
|
$this->Product->create();
|
||
|
|
|
||
|
|
if ($this->Product->save($this->data)) {
|
||
|
|
$this->Session->setFlash(__('The Product has been saved', true));
|
||
|
|
$this->redirect(array('action'=>'index'));
|
||
|
|
} else {
|
||
|
|
$this->Session->setFlash(__('The Product could not be saved. Please, try again.', true));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$principles = $this->Product->Principle->find('list');
|
||
|
|
$this->set(compact('principles'));
|
||
|
|
}
|
||
|
|
|
||
|
|
function edit($id = null) {
|
||
|
|
if (!$id && empty($this->data)) {
|
||
|
|
$this->Session->setFlash(__('Invalid Product', true));
|
||
|
|
$this->redirect(array('action'=>'index'));
|
||
|
|
}
|
||
|
|
if (!empty($this->data)) {
|
||
|
|
if ($this->Product->save($this->data)) {
|
||
|
|
$this->Session->setFlash(__('The Product has been saved', true));
|
||
|
|
$this->redirect(array('action'=>'index'));
|
||
|
|
} else {
|
||
|
|
$this->Session->setFlash(__('The Product could not be saved. Please, try again.', true));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (empty($this->data)) {
|
||
|
|
$this->data = $this->Product->read(null, $id);
|
||
|
|
}
|
||
|
|
$principles = $this->Product->Principle->find('list');
|
||
|
|
$this->set(compact('principles'));
|
||
|
|
}
|
||
|
|
|
||
|
|
function delete($id = null) {
|
||
|
|
if (!$id) {
|
||
|
|
$this->Session->setFlash(__('Invalid id for Product', true));
|
||
|
|
$this->redirect(array('action'=>'index'));
|
||
|
|
}
|
||
|
|
if ($this->Product->del($id)) {
|
||
|
|
$this->Session->setFlash(__('Product deleted', true));
|
||
|
|
$this->redirect(array('action'=>'index'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
?>
|