Skip to content

Instantly share code, notes, and snippets.

@converge
Created July 16, 2014 19:22
Show Gist options
  • Save converge/5f10e34646c62bcef203 to your computer and use it in GitHub Desktop.
Save converge/5f10e34646c62bcef203 to your computer and use it in GitHub Desktop.
<?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