如何在 cakephp 3 中获取 table 的类名?

How can I get the className of my table in cakephp 3?

在我的 AcosTable.php 我有

$this->hasMany('ChildAcos', [
    'alias' => 'ChildAcos',
    'className' => 'Acos',
    'foreignKey' => 'parent_id'
]);

我需要在 appController 中使用 table name(className 属性)。在我的 appController 中我有

$associations = $this->{$this->modelClass}->associations();
foreach ($associations->type('HasMany') as $item) {
    $options['name'] = $item->name();             //ChildAcos
    $options['foreignKey'] = $item->foreignKey(); //parent_id
    //$options['className'] = $item->?();         //Acos
    $hasMany[] = $options;
}

如何检索类名?

与所有其他关联选项相反,似乎没有办法掌握 Association::$_className 的值,您可能想在 GitHub 报告这一点,我认为让这个也可以访问(至少可读)不会有什么坏处。

目前看来,您所能做的就是从目标表中找出完整的类名,例如:

$fqn = get_class($item->target());
$parts = namespaceSplit($fqn);
$className = substr(end($parts), 0, -5);