-1

When I view my list in my admin I would like to be able to make sure the controller name is sorted asc

Currently it does not sort alphabetically

 'name' => ucwords(str_replace('_', ' ', $controller)), 

Function

public function index() {
    $data['title'] = "User Group Permissions";

    $controller_files = $this->get_installed_permissions('name'); 

    $data['controller_files'] = array();

    $files = glob(FCPATH . 'application/modules/admin/controllers/*/*.php');

    if ($files) {

        foreach ($files as $file) {

            $controller =  basename(strtolower($file), '.php');

            $modules = $this->get_permissions_by_controller($controller);

            $module_data = array();

            foreach ($modules as $module) {
                $module_data[] = array(
                    'user_group_id' => $module['user_group_id'],
                    'name' => ucwords(str_replace('_', ' ', $controller) . ' > ' . $module['name']),
                    'edit' => site_url('admin/extension/permissions/update' .'/'. $controller .'/'. $module['user_group_id']),
                    'delete' => '' 
                );
            }

            $data['controller_files'][] = array(
                'name' => ucwords(str_replace('_', ' ', $controller)),
                'controller' => $controller,
                'module'    => $module_data,
                'install' => site_url('admin/extension/permissions/install') .'/'.$controller,
                'installed' => in_array($controller, $controller_files)
            );

        }
    }

    $this->load->view('template/extension/extension_permissions', $data);
}
3
Contributors
2
Replies
21
Views
2 Years
Discussion Span
Last Post by Kyle Wiering
1

To Ips's point, I would recommend asort.
It also helps to reduce the 'scope' of the issue. You have a double array, but only the sort on the outer array is relevant. I've removed everything else. Now, you may not need asort if you don't care about the index. The 'printout' from the following method should clarify.

  public function ExplanationIndex()
    {
        $data = [ // initialize everything
            'title' => 'User Group Permissions'            
        ]; 

        // sample 'file' list, unsorted.
        $file_list = ['z','y','x','w','a','b','c','d','e'];
        echo 'before';
        print_r($file_list);

        // initialize the array
        $controller_file_list = [];
        foreach ($file_list as $file)
        {
            $controller_file_list[] = [
                'name' =>           $file.'name',
                'controller' =>     $file.'controller',
                'module' =>         [rand(0,100),rand(0,100),rand(0,100),rand(0,100),rand(0,100)],
                'install' =>        $file,
                'installed' =>      (bool)rand(0,1)
            ];
        }

        asort($controller_file_list);        
        echo 'after';
        print_r($controller_file_list);
        $data['controller_files'] = $controller_file_list;
    }

Edited by Kyle Wiering: (asort, not array sort)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.