Skip to content

Instantly share code, notes, and snippets.

Created May 20, 2016 12:29
Show Gist options
  • Save anonymous/c6ac8712102bef1b205f22871cd1cb08 to your computer and use it in GitHub Desktop.
Save anonymous/c6ac8712102bef1b205f22871cd1cb08 to your computer and use it in GitHub Desktop.
<?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