flexible table classes in controllers for rest of tables
This commit is contained in:
@@ -20,7 +20,7 @@ use CakeProducts\Service\CatalogManagerService;
|
||||
*/
|
||||
class ProductCatalogsController extends AppController
|
||||
{
|
||||
protected ?Table $_productCatalogsTable = null;
|
||||
protected ?Table $_table = null;
|
||||
|
||||
/**
|
||||
* Index method
|
||||
@@ -29,7 +29,7 @@ class ProductCatalogsController extends AppController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->getProductCatalogsTable()->find();
|
||||
$query = $this->getTable()->find();
|
||||
$productCatalogs = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productCatalogs'));
|
||||
@@ -48,7 +48,7 @@ class ProductCatalogsController extends AppController
|
||||
if (Configure::read('CakeProducts.internal.syncExternally', false)) {
|
||||
$contain[] = 'ExternalProductCatalogs';
|
||||
}
|
||||
$productCatalog = $this->getProductCatalogsTable()->get($id, contain: $contain);
|
||||
$productCatalog = $this->getTable()->get($id, contain: $contain);
|
||||
$this->set(compact('productCatalog'));
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class ProductCatalogsController extends AppController
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productCatalogsTable = $this->getProductCatalogsTable();
|
||||
$productCatalogsTable = $this->getTable();
|
||||
$productCatalog = $productCatalogsTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
|
||||
@@ -86,7 +86,7 @@ class ProductCatalogsController extends AppController
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productCatalogsTable = $this->getProductCatalogsTable();
|
||||
$productCatalogsTable = $this->getTable();
|
||||
$productCatalog = $productCatalogsTable->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData());
|
||||
@@ -110,7 +110,7 @@ class ProductCatalogsController extends AppController
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productCatalogsTable = $this->getProductCatalogsTable();
|
||||
$productCatalogsTable = $this->getTable();
|
||||
$productCatalog = $productCatalogsTable->get($id);
|
||||
if ($productCatalogsTable->delete($productCatalog)) {
|
||||
$this->Flash->success(__('The product catalog has been deleted.'));
|
||||
@@ -126,15 +126,15 @@ class ProductCatalogsController extends AppController
|
||||
*
|
||||
* @return Table
|
||||
*/
|
||||
public function getProductCatalogsTable()
|
||||
public function getTable()
|
||||
{
|
||||
if ($this->_productCatalogsTable instanceof Table) {
|
||||
return $this->_productCatalogsTable;
|
||||
if ($this->_table instanceof Table) {
|
||||
return $this->_table;
|
||||
}
|
||||
$this->_productCatalogsTable = TableRegistry::getTableLocator()->get(
|
||||
$this->_table = TableRegistry::getTableLocator()->get(
|
||||
Configure::read('CakeProducts.ProductCatalogs.table', 'CakeProducts.ProductCatalogs')
|
||||
);
|
||||
|
||||
return $this->_productCatalogsTable;
|
||||
return $this->_table;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user