Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all tables in cakePHP 3.x

I have been trying to work this one out. In cakePHP 2 I could use:

$tables = ConnectionManager::getDataSource('default')->listSources();

But in CakePHP 3.x I can't work out what to use? I have looked at the link cakephp get schema for list of tables

Unfortunately it doesnt help with cakePHP 3.0?

like image 399
Keni Williams Avatar asked May 15 '15 08:05

Keni Williams


People also ask

What is beforeFilter in cakephp?

The beforeFilter() method will be called for missing actions, and scaffolded actions. Controller::beforeRender() Called after controller action logic, but before the view is rendered. This callback is not used often, but may be needed if you are calling render() manually before the end of a given action.

How can I order in cakephp?

To apply ordering, you can use the order method: $query = $articles->find() ->order(['title' => 'ASC', 'id' => 'ASC']); When calling order() multiple times on a query, multiple clauses will be appended. However, when using finders you may sometimes need to overwrite the ORDER BY .


2 Answers

We can get list of table in cakephp3 using very similar pattern as

$tables = ConnectionManager::get('default')->schemaCollection()->listTables();
like image 51
Abhishek Avatar answered Oct 11 '22 16:10

Abhishek


I just had the same problem. Try using the code below

TableRegistry::exists($model);
like image 43
Tiago Agenor Avatar answered Oct 11 '22 17:10

Tiago Agenor