How to get table / table columns from an entity object in cakephp 3?

Let's say I have a boniced \Cake\ORM\Entityobject - $kablammoI can confirm and make sure that it has an associated repository by doing the following:

use Cake\ORM\Entity;

// ..snip

if ($kablammo instanceOf Entity && !empty($kablammo->source())) {
    $repository = $kablammo->source();
    // ... what do I do here to get the table schema info/columns?
}

I would like to be able to browse the table columns for this Entity-related table basically. What is the best way to do this? Am I already wrong about this?

+4
source share
1 answer

I think I get it.

use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;

// ..snip

if ($kablammo instanceOf Entity && !empty($kablammo->source())) {
    $repository = $kablammo->source();
    $table = TableRegistry::get($repository);
    debug($table->schema());
}

At least I'm on the right track right now.

+7
source

Source: https://habr.com/ru/post/1584144/


All Articles