Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting Magento按文件名对媒体文件夹文件进行排序_Sorting_Magento_Media - Fatal编程技术网

Sorting Magento按文件名对媒体文件夹文件进行排序

Sorting Magento按文件名对媒体文件夹文件进行排序,sorting,magento,media,Sorting,Magento,Media,我想按文件名对媒体文件夹文件进行排序。我尝试了 $collection = $this->getCollection($path) ->setCollectDirs(false) ->setCollectFiles(true) ->setCollectRecursively(false) ->setOrder('filename', Varien_Data_Collection::SORT_ORDER_

我想按文件名对媒体文件夹文件进行排序。我尝试了

$collection = $this->getCollection($path)
        ->setCollectDirs(false)
        ->setCollectFiles(true)
        ->setCollectRecursively(false)
        ->setOrder('filename', Varien_Data_Collection::SORT_ORDER_ASC);
但它不区分大小写,它先对所有大写单词进行排序,然后再对小写单词进行排序。(苹果,蝙蝠,苹果)


请帮忙

您必须重写lib/Varien/Data/Collection/Filesystem.php 和改变功能

protected function _usort($a, $b)
    {
        foreach ($this->_orders as $key => $direction) {
            $result = $a[$key] > $b[$key] ? 1 : ($a[$key] < $b[$key] ? -1 : 0);
            return (self::SORT_ORDER_ASC === strtoupper($direction) ? $result : -$result);
            break;
        }
}
protectedfunction\u usort($a,$b)
{
foreach($this->\按$key=>$direction排序){
$result=$a[$key]>$b[$key]?1:($a[$key]<$b[$key]?-1:0);
返回(self::SORT\u ORDER\u ASC===strotupper($direction)$result:-$result);
打破
}
}
请尝试以下操作:
-在magento根目录中创建一个
test.php
文件。
-将媒体文件夹的名称更改为
$sub_dir
变量

<?php
        require_once 'app/Mage.php';
        Mage::app();

        $file = new Varien_Io_File();
        $sub_dir = "wysiwyg/new";
        $dir = Mage::getBaseDir('media') . DS . $sub_dir . DS;
        $file->open(array('path' => $dir));
        $fileDetails = $file->ls();

        $allFiles = array();
        foreach ($fileDetails as $value) {
            $allFiles[] = $value['text'];
        }

        echo "<pre>";
        print_r($allFiles);
        echo "</pre>";
    ?>