7 Commits

4 changed files with 106 additions and 1 deletions

1
.gitignore vendored
View File

@@ -2,6 +2,7 @@
/composer.phar /composer.phar
/phpunit.xml /phpunit.xml
/.phpunit.result.cache /.phpunit.result.cache
/.phpunit.cache
/phpunit.phar /phpunit.phar
/config/Migrations/schema-dump-default.lock /config/Migrations/schema-dump-default.lock
/vendor/ /vendor/

View File

@@ -0,0 +1,70 @@
<?php
namespace CheeseCake\Controller\Traits;
use Cake\Core\Configure;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
trait OverrideTableTrait
{
/**
* @var Table|null
*/
protected ?Table $_table = null;
/**
* This object's default table alias.
*
* @var string|null
*/
protected ?string $defaultTable = null;
/**
* @var string
*/
protected string $_tableConfigKey = '';
/**
* Gets the table instance
*
* @return Table
*/
public function getTable(string $tableName = null)
{
if ($this->_table instanceof Table) {
return $this->_table;
}
$this->getTableConfigKey();
$table = $tableName;
if (!isset($table)) {
$table = $this->defaultTable;
if (Configure::read($this->_tableConfigKey)) {
$table = Configure::read($this->_tableConfigKey);
}
}
$this->_table = TableRegistry::getTableLocator()->get($table);
return $this->_table;
}
protected function getTableConfigKey()
{
if (!$this->_tableConfigKey) {
$this->_tableConfigKey = $this->getPlugin() . '.' . $this->defaultTable . '.table';
}
return $this->_tableConfigKey;
}
/**
* Set the users table
*
* @param Table $table table
* @return void
*/
public function setTable(Table $table)
{
$this->_table = $table;
}
}

View File

@@ -24,7 +24,7 @@
<?= $this->Html->link(__('New {{ singularHumanName }}'), ['action' => 'add'], ['class' => 'button float-right']) ?> <?= $this->Html->link(__('New {{ singularHumanName }}'), ['action' => 'add'], ['class' => 'button float-right']) ?>
{% set done = [] %} {% set done = [] %}
<h3><?= __('{{ pluralHumanName }}') ?></h3> <h3><?= __('{{ pluralHumanName }}') ?></h3>
<div class="table-responsive"> <div class="table-responsive" id="table-container">
<table> <table>
<thead> <thead>
<tr> <tr>

View File

@@ -0,0 +1,34 @@
<?php declare(strict_types=1);
namespace TestApp;
use Cake\Http\BaseApplication;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\Middleware\RoutingMiddleware;
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;
class Application extends BaseApplication {
/**
* @param \Cake\Routing\RouteBuilder $routes
*
* @return void
*/
public function routes(RouteBuilder $routes): void {
$routes->scope('/', function(RouteBuilder $routes) {
$routes->fallbacks(DashedRoute::class);
});
}
/**
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to set in your App Class
* @return \Cake\Http\MiddlewareQueue
*/
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue {
$middlewareQueue->add(new RoutingMiddleware($this));
return $middlewareQueue;
}
}