Well... I'm out of ideas on what to write about. Do you have any ideas? Please, write me in any comment section you find, and I will do my best to tell you about that particular subject

Step 3.3 – Administer users with Ion Auth

Created at: February 4, 2015; Last update: July 20, 2015

This tutorial is part of a larger one, called Create a CMS with CodeIgniter 3. So, if you don’t understand how we’ve got to this point, I would advise you to try and read the previous tutorials. At the end of next tutorial I will post an archive with what we’ve done so far.

$this->session->set_flashdata('message','You are not allowed to visit the Groups page');

redirect('admin','refresh');

}

}

publicfunctionindex()

{

}

publicfunctioncreate()

{

}

publicfunctionedit()

{

}

publicfunctiondelete()

{

}

}

We will start by working at the list of users. We will display that in the index() method. Also, let’s allow this method to receive a group id so that when this is set the list will only show the users inside that group:

PHP

1

2

3

4

5

6

publicfunctionindex($group_id=NULL)

{

$this->data['page_title']='Users';

$this->data['users']=$this->ion_auth->users($group_id)->result();

$this->render('admin/users/list_users_view');

}

As you can see, to retrieve the users we’ve used the Ion Auth’s users() method. Now let’s create our list_users_view.php file inside application/views/admin/users directory:

As you can see, I didn’t allow the user to delete himself (in most parts of the world the suicide is forbidden :))). If you remember, in a previous tutorial we’ve created $current_user object in the Admin_Controller. Now we’ve accessed this object to verify if the current user is the user in the list. We will not allow him/her to change anything regarding himself. He will be able to change this in the personal profile page.

But… we should return to the edit() method because we actually need to do some form validation callbacks for the username and email. We need to make sure that if those are changed by the admins, they do not already exist in the users table. I leave this to you.

The delete page

The delete() method

PHP

1

2

3

4

5

6

7

8

9

10

11

12

13

publicfunctiondelete($user_id=NULL)

{

if(is_null($user_id))

{

$this->session->set_flashdata('message','There\'s no user to delete');

}

else

{

$this->ion_auth->delete_user($user_id);

$this->session->set_flashdata('message',$this->ion_auth->messages());

}

redirect('admin/users','refresh');

}

Cool, finished the the Users controller too.

But let’s return for a moment to the application/views/admin/groups/list_groups_view.php and make the group name clickable so that the links will send to the users of that group:

Hello, did you download the latest version of the Ion Auth library from Github (https://github.com/benedmunds/CodeIgniter-Ion-Auth)? Because from the time I’ve posted the tutorial until now a lot of changes have been made to the library in order to permit exactly what you ask.