Skip to content

Instantly share code, notes, and snippets.

@joshuaso91
Created May 29, 2017 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuaso91/f65fe61e4e3e75ae72008cbb17e6c6bc to your computer and use it in GitHub Desktop.
Save joshuaso91/f65fe61e4e3e75ae72008cbb17e6c6bc to your computer and use it in GitHub Desktop.
<?php
namespace App\Controller;
use App\Controller\AppController;
/**
* Orders Controller
*
* @property \App\Model\Table\OrdersTable $Orders
*/
class OrdersController extends AppController
{
/**
* Index method
*
* @return \Cake\Network\Response|null
*/
public function index()
{
$this->paginate = [
'contain' => ['Stores', 'Users', 'ProductStores']
];
$orders = $this->paginate($this->Orders);
$this->set(compact('orders'));
$this->set('_serialize', ['orders']);
}
/**
* View method
*
* @param string|null $id Order id.
* @return \Cake\Network\Response|null
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
{
$order = $this->Orders->get($id, [
'contain' => ['Stores', 'Users', 'ProductStores', 'Invoices']
]);
$this->set('order', $order);
$this->set('_serialize', ['order']);
}
/**
* Add method
*
* @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$order = $this->Orders->newEntity();
if ($this->request->is('post')) {
$order = $this->Orders->patchEntity($order, $this->request->data);
if ($this->Orders->save($order)) {
$this->Flash->success(__('The {0} has been saved.', 'Order'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The {0} could not be saved. Please, try again.', 'Order'));
}
}
$stores = $this->Orders->Stores->find('list', ['limit' => 200]);
$users = $this->Orders->Users->find('list', ['limit' => 200]);
$productStores = $this->Orders->ProductStores->find('list', ['limit' => 200]);
$this->set(compact('order', 'stores', 'users', 'productStores'));
$this->set('_serialize', ['order']);
}
/**
* Edit method
*
* @param string|null $id Order id.
* @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Network\Exception\NotFoundException When record not found.
*/
public function edit($id = null)
{
$order = $this->Orders->get($id, [
'contain' => []
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$order = $this->Orders->patchEntity($order, $this->request->data);
if ($this->Orders->save($order)) {
$this->Flash->success(__('The {0} has been saved.', 'Order'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The {0} could not be saved. Please, try again.', 'Order'));
}
}
$stores = $this->Orders->Stores->find('list', ['limit' => 200]);
$users = $this->Orders->Users->find('list', ['limit' => 200]);
$productStores = $this->Orders->ProductStores->find('list', ['limit' => 200]);
$this->set(compact('order', 'stores', 'users', 'productStores'));
$this->set('_serialize', ['order']);
}
/**
* Delete method
*
* @param string|null $id Order id.
* @return \Cake\Network\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$order = $this->Orders->get($id);
if ($this->Orders->delete($order)) {
$this->Flash->success(__('The {0} has been deleted.', 'Order'));
} else {
$this->Flash->error(__('The {0} could not be deleted. Please, try again.', 'Order'));
}
return $this->redirect(['action' => 'index']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment