2 Commits

2 changed files with 76 additions and 1 deletions

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

@@ -62,7 +62,12 @@ class ActiveLinkHelper extends Helper
} }
foreach ($target as $targetKey => $targetValue) { foreach ($target as $targetKey => $targetValue) {
if (is_array($targetValue)) { if (is_array($targetValue)) {
return 'test'; if (!in_array($currentUrl[$targetKey], $targetValue)) {
return $this->Html->link($title, $url, $options);
}
$options['class'] = $this->_addClass($options);
return $this->Html->link($title, $url, $options);
} }
if (!array_key_exists($targetKey, $currentUrl) || $targetValue != $currentUrl[$targetKey]) { if (!array_key_exists($targetKey, $currentUrl) || $targetValue != $currentUrl[$targetKey]) {
return $this->Html->link($title, $url, $options); return $this->Html->link($title, $url, $options);