cake如何使用array_component函数找到扩展名为.txt的文件,并将其放入cakephp表单的select


cakeHow to find files with .txt extension and put them into a cake php form select input element by using the array_combine function?

我想知道如何在一个包含.txt扩展名的目录中找到所有文件,然后创建一个带有结果的array_component。

如果您想获得下拉选项的文本,那么您应该使数组索引与关联值相同:

$files = glob($dir."/*.[tT][xX][tT]");
$correctFiles = array_combine($files,$files);
Choose text file: <?php echo $this->Form->select('textDrop', array('options' => $correctFiles, 'style' => 'width: 150px;', 'id' => 'textDrop')); ?>