Search code examples
codeignitergrocery-crudcodeigniter-hmvc

Codeigniter HMVC listing with where condition


I am new in CI hmvc and i am using CI generate_crud() method like below :

public function index()
    {
        $crud = $this->generate_crud('users');
        $crud->columns('groups', 'username', 'email', 'first_name', 'last_name', 'company', 'no_employee', 'active');
        $this->unset_crud_fields('ip_address', 'last_login');

        // only webmaster and admin can change member groups
        if ($crud->getState()=='list' || $this->ion_auth->in_group(array('webmaster', 'admin')))
        {
            $crud->set_relation_n_n('groups', 'users_groups', 'groups', 'user_id', 'group_id', 'name');
        }

        // only webmaster and admin can reset user password
        if ($this->ion_auth->in_group(array('webmaster', 'admin')))
        {
            $crud->add_action('Reset Password', '', 'admin/user/reset_password', 'fa fa-repeat');
            $crud->add_action('Edit', '', 'admin/user/edit_user', 'edit-icon');
        }

        // disable direct create / delete Frontend User
        $crud->unset_add();

        $this->mPageTitle = 'Users';
        $this->render_crud();
    }

This returns me the list of all active and inactive users but i want only active users in list. How can i modify my code with so that i can get list of only active users.


Solution

  • You need to set the condition for the active = true

    $crud->where('active',true);
    

    This will only return the active columns.