User profile tables allow you to have unique data that is tied to your users, while acknowledging that not all users are the same. For instance, you may need to store different types of data for a customer versus an admin, or one type of employee versus another. By default Community Auth no longer integrates profile tables, but setting them up is simple, as you can see by the rather short length of this blog post.

The goal of this blog post is to show you how to retrieve profile data and add it to the other authentication variables that Community Auth makes available.

Please note: Before 11/9/2015 Community Auth had some class visibility settings that may need to be adjusted if you’re trying to follow along, and if you’re version of Community Auth is older. See the following link for details:

User Profiles Need a Table

For the purposes of showing you how to retreive some profile data, I’m creating a customer profile table. In the default authentication configuration that comes with Community Auth, “customer” is a user role, and is associated with auth level #1. Because this is just an example, I’ve only added two profile fields, first_name and last_name. Get started by creating the new customer_profiles table:

Make sure to add the table to Community Auth’s DB tables config file. This is necessary if you plan to use my code below.

$config['customer_profiles'] = 'customer_profiles';

MY_Controller

Community Auth comes with a MY_Controller, and you need to add some stuff to it. Notice that when you are done, you’ll be able to access the selected customer profile data in your controllers, views, and anywhere that CodeIgniter config is available.

Make sure to tell Community Auth to use My_auth_model by changing Community Auth’s model in config/authentication.php:

$config['declared_auth_model'] = 'my_auth_model';

Conclusion

The code in this blog post should have allowed you to implement user profiles into your installation of Community Auth. This is by no means the only way to do this, but kept simple for the sake of showing that it is simple to do. Other things, like creating the profile records, updating the profiles records, and other application specific details have been left out on purpose.