public function templateData()
{
$namespace = Configure::read('App.namespace');
if ($this->plugin) {
$namespace = $this->_pluginNamespace($this->plugin);
}
$table = Inflector::tableize($this->args[0]);
if (!empty($this->params['table'])) {
$table = $this->params['table'];
}
$records = false;
if ($this->param('data')) {
$limit = (int) $this->param('limit');
$fields = $this->param('fields') ?: '*';
if ($fields !== '*') {
$fields = explode(',', $fields);
}
$connection = ConnectionManager::get($this->connection);
$query = $connection->newQuery()->from($table)->select($fields);
if ($limit) {
$query->limit($limit);
}
$records = $connection->execute($query)->fetchAll('assoc');
$records = $this->prettifyArray($records);
}
return ['className' => $this->BakeTemplate->viewVars['name'], 'namespace' => $namespace, 'records' => $records, 'table' => $table];
}