Created
July 16, 2014 19:16
-
-
Save converge/78c40191222c188ef58e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('AppController', 'Controller'); | |
/** | |
* PriceLists Controller | |
* | |
* @property PriceList $PriceList | |
*/ | |
class PriceListsController extends AppController { | |
var $layout = 'default_notop'; | |
/** | |
* index method | |
* | |
* @return void | |
*/ | |
public function index() { | |
$this->PriceList->recursive = 0; | |
$this->set('priceLists', $this->paginate()); | |
} | |
/** | |
* view method | |
* | |
* @throws NotFoundException | |
* @param string $id | |
* @return void | |
*/ | |
public function view($id = null) { | |
$this->PriceList->id = $id; | |
if (!$this->PriceList->exists()) { | |
throw new NotFoundException(__('Invalid price list')); | |
} | |
$this->set('priceList', $this->PriceList->read(null, $id)); | |
} | |
/** | |
* add method | |
* | |
* @return void | |
*/ | |
public function add() { | |
if ($this->request->is('post')) { | |
$this->PriceList->create(); | |
if ($this->PriceList->save($this->request->data)) { | |
$this->Session->setFlash(__('The price list has been saved')); | |
$this->redirect(array('action' => 'index')); | |
} else { | |
$this->Session->setFlash(__('The price list could not be saved. Please, try again.')); | |
} | |
} | |
} | |
/** | |
* edit method | |
* | |
* @throws NotFoundException | |
* @param string $id | |
* @return void | |
*/ | |
public function edit($id = null) { | |
$this->PriceList->id = $id; | |
if (!$this->PriceList->exists()) { | |
throw new NotFoundException(__('Invalid price list')); | |
} | |
if ($this->request->is('post') || $this->request->is('put')) { | |
if ($this->PriceList->save($this->request->data)) { | |
$this->Session->setFlash(__('The price list has been saved')); | |
$this->redirect(array('action' => 'index')); | |
} else { | |
$this->Session->setFlash(__('The price list could not be saved. Please, try again.')); | |
} | |
} else { | |
$this->request->data = $this->PriceList->read(null, $id); | |
} | |
} | |
/** | |
* delete method | |
* | |
* @throws MethodNotAllowedException | |
* @throws NotFoundException | |
* @param string $id | |
* @return void | |
*/ | |
public function delete($id = null) { | |
if (!$this->request->is('post')) { | |
throw new MethodNotAllowedException(); | |
} | |
$this->PriceList->id = $id; | |
if (!$this->PriceList->exists()) { | |
throw new NotFoundException(__('Invalid price list')); | |
} | |
if ($this->PriceList->delete()) { | |
$this->Session->setFlash(__('Price list deleted')); | |
$this->redirect(array('action' => 'index')); | |
} | |
$this->Session->setFlash(__('Price list was not deleted')); | |
$this->redirect(array('action' => 'index')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment