-
-
Save anonymous/c6ac8712102bef1b205f22871cd1cb08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace CrudView\View\Cell; | |
use Cake\Datasource\ConnectionManager; | |
use Cake\Utility\Inflector; | |
use Cake\View\Cell; | |
class TablesListCell extends Cell | |
{ | |
/** | |
* Default cell method. | |
* | |
* @param array $tables Tables list. | |
* @param array $blacklist Blacklisted tables list. | |
* @return array | |
*/ | |
public function display($tables = null, $blacklist = null) | |
{ | |
//Option 1 start | |
$blacklist[] = 'phinxlog'; | |
//Option 1 end | |
if (empty($tables)) { | |
$connection = ConnectionManager::get('default'); | |
$schema = $connection->schemaCollection(); | |
$tables = $schema->listTables(); | |
ksort($tables); | |
if (!empty($blacklist)) { | |
$tables = array_diff($tables, $blacklist); | |
} | |
} | |
//Option 2 start | |
$phinxLogKey = array_search('phinxlog', $tables); | |
if ($phinxLogKey !== false) { | |
unset($tables[$phinxLogKey]); | |
} | |
//Option 2 end | |
debug($tables); | |
die; | |
$normal = []; | |
foreach ($tables as $table => $config) { | |
if (is_string($config)) { | |
$config = ['table' => $config]; | |
} | |
if (is_int($table)) { | |
$table = $config['table']; | |
} | |
$config += [ | |
'action' => 'index', | |
'title' => Inflector::humanize($table), | |
'controller' => Inflector::camelize($table) | |
]; | |
$normal[$table] = $config; | |
} | |
return $this->set('tables', $normal); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment