【发布时间】:2017-02-20 16:32:58
【问题描述】:
为基于 PHP 的电子商务系统使用自定义模板(期刊 2)。 在控制面板中,有一个加载自定义模块的部分。 问题是,模块是按照创建的顺序呈现的,这使得很难找到合适的模块。 我想按字母顺序对它们进行排序。
如何以及在哪里可以向此函数添加按名称排序功能?
public function all() {
if (isset($this->get_data['module_type'])) {
$module_type = $this->db->escape('journal2_' . $this->get_data['module_type']);
$query = $this->db->query('SELECT * FROM ' . DB_PREFIX . 'journal2_modules WHERE module_type = "' . $module_type . '"');
} else {
$query = $this->db->query('SELECT * FROM ' . DB_PREFIX . 'journal2_modules');
}
foreach ($query->rows as &$row) {
$row['module_data'] = json_decode($row['module_data'], true);
if (is_array($row['module_data'])) {
foreach($row['module_data'] as $key => &$value) {
if (!in_array($key, array('module_name', 'module_type'))) {
unset($row['module_data'][$key]);
}
}
}
}
return $query->rows;
}
提前致谢!
【问题讨论】: