Reputation: 848
I need to get a list of all models of my application (including plugins).
In Cake 2 you could use App::objects('Model');
. How am I able to do this in cake 3.x?
Thanks!
Bob
Upvotes: 4
Views: 1279
Reputation: 29141
I'm not sure if this helps, but it should give you about all the information you're going to be able to get. To the point of the commenter(s), there aren't really "Models" in CakePHP 3 - there are Tables and Entities.
use Cake\Datasource\ConnectionManager;
use Cake\ORM\TableRegistry;
// ...
$tables = ConnectionManager::get('default')->schemaCollection()->listTables();
foreach($tables as $key => $table) {
$tableData = TableRegistry::get($table);
debug($tableData);
}
Returns this for each table:
object(App\Model\Table\PhotosTable) {
'registryAlias' => 'photos',
'table' => 'photos',
'alias' => 'photos',
'entityClass' => '\Cake\ORM\Entity',
'associations' => [
(int) 0 => 'tags',
(int) 1 => 'categorized'
],
'behaviors' => [
(int) 0 => 'Timestamp',
(int) 1 => 'Sluggable'
],
'defaultConnection' => 'default',
'connectionName' => 'default'
}
Upvotes: 2