我需要从每个插件的文件夹中加载索引.php文件。有主文件夹"插件",里面有子文件夹(插件),例如博客、成员等。在每个插件文件夹中都有一个我需要加载的索引.php文件。如何加载目录并搜索这些文件。插件文件夹不是静态的,可能会更改。
我试过什么
$dir_iterator = new RecursiveDirectoryIterator($this->plugin_dir);
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
// could use CHILD_FIRST if you so wish
foreach ($iterator as $file) {
echo $file, "'n";
}
和。。全球功能(没有多大帮助
$list = glob('index.php', GLOB_BRACE);
foreach($list as $files){
echo $files;
}
print_r($list);
我使用了双重列表方式。
private function loadPlugins(){
$dir = array_diff(scandir($this->plugin_dir), array('..', '.'));
foreach($dir as $ds){
$list = glob($this->plugin_dir.'/'.$ds.'/index.php', GLOB_BRACE);
foreach($list as $files){
require $files;
}
}
}