Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 28d5856908 | |||
|
|
30baf4a2a7 | ||
|
|
0dba6fb137 | ||
| 94ad49396a | |||
|
|
5672e3dbf7 | ||
|
|
f604754a98 | ||
|
|
31ae4a394c |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -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/
|
||||||
|
|||||||
70
src/Controller/Traits/OverrideTableTrait.php
Normal file
70
src/Controller/Traits/OverrideTableTrait.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
|
|||||||
34
tests/test_app/src/Application.php
Normal file
34
tests/test_app/src/Application.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user