CakePHP 3:获取所有表对象的列表时排除供应商表

CakePHP 3:获取所有表对象的列表时排除供应商表,cakephp,cakephp-3.x,Cakephp,Cakephp 3.x,在我的数据库中,我有一些插件创建的表。我只需要在下拉列表中显示我的模型 在bootstrap.php中: Configure::write('ReportManager.modelIgnoreList',array( 'acl_phinxlog', 'acos', 'aros', 'aros_acos', 'audits', 'burzum_file_storage_phinxlog', 'burzum_user_tools_phinxlog', 'cake_d_c_users_phinxlog

在我的数据库中,我有一些插件创建的表。我只需要在下拉列表中显示我的模型

在bootstrap.php中:

Configure::write('ReportManager.modelIgnoreList',array(
'acl_phinxlog',
'acos',
'aros',
'aros_acos',
'audits',
'burzum_file_storage_phinxlog',
'burzum_user_tools_phinxlog',
'cake_d_c_users_phinxlog',
'file_storage',
'phinxlog',
));
在我的控制器索引函数中:

if (empty($this->data)) {
        $modelIgnoreList = Configure::read('ReportManager.modelIgnoreList'); 
        $models = ConnectionManager::get('default')->schemaCollection()->listTables();
        foreach($models as $key => $model) {
            if ( isset($modelIgnoreList) && is_array($modelIgnoreList)) {
                foreach ($modelIgnoreList as $ignore) {
                    if (isset($models[$ignore])) {
                        unset($models[$ignore]);
                        $modelData = TableRegistry::get($model);
                        debug($modelData);
                    }
                }
            }
        }
    debug($modelIgnoreList);
}
在index.ctp中:

echo $this->Form->create('ReportManager');
    echo '<fieldset>';
    echo '<legend>' . __d('report_manager','New report',true) . '</legend>';        
    echo $this->Form->input('model',array(
        'type'=>'select',            
        'label'=>__d('report_manager','Model',true),
        'options'=>$models,
        'empty'=>__d('report_manager','--Select--',true)
        ));
echo$this->Form->create('ReportManager');
回声';
回显“”__d(‘报告经理’,‘新报告’,正确)。“”;
echo$this->Form->input('model',数组(
'类型'=>'选择',
“标签”=>\uuu d('report\u manager','Model',true),
“选项”=>$models,
'empty'=>\uuu d('report\u manager','--Select--',true)
));

我的结果显示了所有的表格。我的错误在哪里?

您正在使用型号名称而不是键调用
unset
。此外,这里不需要两个
foreach
循环

$models = ConnectionManager::get('default')->schemaCollection()->listTables();
if (isset($modelIgnoreList) && is_array($modelIgnoreList)) {
    foreach($models as $key => $model) {
        if (in_array($model, $modelIgnoreList)) {
            unset($models[$key]);
        }
    }
}
或者,更简单的是,使用内置功能为您处理此问题:

$models = ConnectionManager::get('default')->schemaCollection()->listTables();
if (isset($modelIgnoreList) && is_array($modelIgnoreList)) {
    $models = array_diff($models, $modelIgnoreList);
}

令人惊叹的。第二个对我有用。非常感谢@Greg。我感谢你的帮助:)