User Guide | Getting User Account Data

The flexi auth library functions for getting data from the user account tables.

Get User Account Data

User Account Index | User Account Config | Set User Account Data

Help with Function Parameters

Show / Hide Help

Name: The name of the function parameter (argument).

Data Type: The data type that is expected by the parameter.

  • bool : Requires a boolean value of 'TRUE' or 'FALSE'.
  • string : Requires a textual value.
  • int : Requires a numeric value. It does not matter whether the value is an integer, float, decimal etc.
  • array : Requires an array.

Required: Defines whether the parameter requires a value to be submitted.

Default: Defines the default parameter value that is used if no other value is submitted.

get_user_id()

Get the users id from the session.


Library and Requirements

Available via the lite and standard libraries.

How it Works

The function gets the user id value saved in the users browser session.

Return Values

Failure:FALSE

Success:int

Example
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
get_user_id() What is the user id of the current logged in user? NULL

get_user_identity()

Get the users primary identity from the session.


Library and Requirements

Available via the lite and standard libraries.

How it Works

The function gets the user id value saved in the users browser session.

Return Values

Failure:FALSE

Success:string

Example
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
get_user_identity() What is the primary identity of the current logged in user? NULL

get_user_by_id()

Get all user data by submitting the users id.


Library and Requirements

Available via the lite and standard libraries.

Function Parameters
get_user_by_id(user_id) Help
Name Data Type Required Default Description
user_id int No FALSE Defines the users unique row id from the user account table.
If no value is defined, the function will try to use the user id of the current logged in user.
How it Works

The function uses the defined user id to create an SQL WHERE statement that filters the defined user from the user accounts table.

The SQL query is automatically joined with any other custom user tables (e.g. Profile and address tables in the demo) that have been defined and joined via the config. file. By using the defined joins, the query will return data from all the related custom tables too.

Notes

The SQL query uses GROUP BY on the users id column.
This means that if you have any related custom user tables that may have more than one row of data related to a unique user id, then only the first row will be returned by this function.

If you need to return multiple rows of data per unique user id, then you can use the alternative get_custom_user_data() function.


This function is compatible with flexi auths 'Query Builder' functions.


This function can be chained with CodeIgniters query functions 'result()', 'row()' etc.

Read the Query Result documentation for further information on all the combined flexi auth and CodeIgniter functions that are available.

Return Values

Failure:FALSE

Success:object

Example
// Example #1 : Get all user data for the current logged in user.
$this->flexi_auth->get_user_by_id();
// Example #2 : Get all user data for the user with an id of '101'.
$user_id = 101;
$this->flexi_auth->get_user_by_id($user_id);
// Example of chaining CI's query function 'result()'.
// Read the Query Result documentation for further information on available functions.
$this->flexi_auth->get_user_by_id()->result();

get_user_by_identity()

Get all user data by submitting the users identity.


Library and Requirements

Available via the lite and standard libraries.

Function Parameters
get_user_by_identity(identity) Help
Name Data Type Required Default Description
identity string No FALSE Defines the users identity (Username and/or Email) from the user account table.
If no value is defined, the function will try to use the primary identity of the current logged in user.
How it Works

The function uses the defined user identity (Username and/or Email) to create an SQL WHERE statement that filters the defined user from the user accounts table.

The SQL query is automatically joined with any other custom user tables (e.g. Profile and address tables in the demo) that have been defined and joined via the config. file. By using the defined joins, the query will return data from all the related custom tables too.

Notes

The SQL query uses GROUP BY on the users id column.
This means that if you have any related custom user tables that may have more than one row of data related to a unique user id, then only the first row will be returned by this function.

If you need to return multiple rows of data per unique user id, then you can use the alternative get_custom_user_data() function.

This function is compatible with flexi auths 'Query Builder' functions.



This function can be chained with CodeIgniters query functions 'result()', 'row()' etc.

Read the Query Result documentation for further information on all the combined flexi auth and CodeIgniter functions that are available.

Return Values

Failure:FALSE

Success:object

Example
// Example #1 : Get all user data for the current logged in user.
$this->flexi_auth->get_user_by_identity();
// Example #2 : Get all user data for the user with an email identity of 'custom@email.com'.
$user_identity = 'custom@email.com';
$this->flexi_auth->get_user_by_identity($user_identity);
// Example #3 : Get all user data for the user with a username identity of 'custom_username'.
$user_identity = 'custom_username';
$this->flexi_auth->get_user_by_identity($user_identity);
// Example of chaining CI's query function 'result()'.
// Read the Query Result documentation for further information on available functions.
$this->flexi_auth->get_user_by_identity()->result();

get_users()

Gets data from the user account table and any custom tables that have been related to it.


Library and Requirements

Available via the lite and standard libraries.

Function Parameters
get_users(sql_select, sql_where) Help
Name Data Type Required Default Description
sql_select string | array No FALSE Define the database fields returned via an SQL SELECT statement.
Read the defining SQL documentation for further information.
sql_where string | array No FALSE Set the SQL WHERE statement used to filter the database records to return.
Read the defining SQL documentation for further information.
How it Works

The function uses the defined 'sql_where' argument to create an SQL WHERE statement to filter a list of users from the user accounts table.

The data returned by the query is defined via the 'sql_select' argument. If no columns are specified, all columns will be returned.

The SQL query is automatically joined with any other custom user tables (e.g. Profile and address tables in the demo) that have been defined and joined via the config. file. By using the defined joins, the query can return data from any of the related custom tables.

Notes

The SQL query uses GROUP BY on the users id column.
This means that if you have any related custom user tables that may have more than one row of data related to a unique user id, then only the first row will be returned by this function.

If you need to return multiple rows of data per unique user id, then you can use the alternative get_custom_user_data() function.


This function is compatible with flexi auths 'Query Builder' functions.


This function can be chained with CodeIgniters query functions 'result()', 'row()' etc.

Read the Query Result documentation for further information on all the combined flexi auth and CodeIgniter functions that are available.

Return Values

Failure:FALSE

Success:object

Examples
// Read the defining SQL documentation for further information on setting SQL statements.
$sql_select = array(...);
$sql_where = array(...);

// Example of chaining CI's query function 'result()'.
// Read the Query Result documentation for further information on available functions.
$this->flexi_auth->get_users($sql_select, $sql_where)->result();

get_custom_user_data()

Gets data from the user account table and any custom tables that have been related to it.

The key difference with this function to the get_users() function, is that query results are not automatically grouped (Athough they can be).
This means that a query could return multiple rows from a custom user table that are all related to a unique user id, rather than grouping the data to just one row.

For example, the flexi auth demo includes a customer user address table, to return data on the user and ALL of their addresses, the query should not group rows by the user id.


Library and Requirements

Available via the lite and standard libraries.

Function Parameters
get_custom_user_data(sql_select, sql_where, sql_group_by) Help
Name Data Type Required Default Description
sql_select string | array No FALSE Define the database fields returned via an SQL SELECT statement.
Read the defining SQL documentation for further information.
sql_where string | array No FALSE Set the SQL WHERE statement used to filter the database records to return.
Read the defining SQL documentation for further information.
sql_group_by bool | string | array No FALSE Define whether the returned query rows should be grouped together by a specific table column.
How it Works

The function uses the defined 'sql_where' argument to create an SQL WHERE statement to filter a list of users from the user accounts table.

The data returned by the query is defined via the 'sql_select' argument. If no columns are specified, all columns will be returned.

The SQL query is automatically joined with any other custom user tables (e.g. Profile and address tables in the demo) that have been defined and joined via the config. file. By using the defined joins, the query can return data from any of the related custom tables.

Unlike the similar get_users() function, this function allows data to be grouped by a specific table column, or to not be grouped at all.

Notes

This function is compatible with flexi auths 'Query Builder' functions.


This function can be chained with CodeIgniters query functions 'result()', 'row()' etc.

Read the Query Result documentation for further information on all the combined flexi auth and CodeIgniter functions that are available.

Return Values

Failure:FALSE

Success:object

Examples
// Read the defining SQL documentation for further information on setting SQL statements.
$sql_select = array(...);
$sql_where = array(...);
$sql_group_by = array(...);

// Example of chaining CI's query function 'result()'.
// Read the Query Result documentation for further information on available functions.
$this->flexi_auth->get_custom_user_data($sql_select, $sql_where, $sql_group_by)->result();

search_users()

Gets data from the user account table via a keyword based search query.


Library and Requirements

Available via the standard library.

Function Parameters
search_users(search_query, exact_match, sql_select, sql_where, sql_group_by) Help
Name Data Type Required Default Description
search_query string | array Yes FALSE Defines the search terms used to query the user account table.
exact_match bool No FALSE Define whether all keywords within the search query must be in the matched records.
Example: For a search query of "John Smith", an exact match would not return a record matching the name "John".
sql_select string | array No FALSE Define the database fields returned via an SQL SELECT statement.
Read the defining SQL documentation for further information.
sql_where string | array No FALSE Set the SQL WHERE statement used to filter the database records to return.
Read the defining SQL documentation for further information.
sql_group_by bool | string | array No TRUE Define whether the returned query rows should be grouped together by a specific table column.
By default the function will group records by the user id.
How it Works

The function works in a similar way to the other user query functions within the library, with the exception that it allows the returned results to be additionally filtered via search terms.

The submitted search term is split into individual terms that are then each matched against specific user table columns that have been defined via the setting 'search_user_cols' in the libraries config. file.

If the function has defined the query to only return exact matches, then the SQL function will only return records where every individual term is matched to each record.

Notes

By default, the function will group users by their user id using an SQL GROUP BY statement.

This means that if you have any related custom user tables that may have more than one row of data related to a unique user id (Example: multiple addresses per user), then by default, only the first row will be returned.

The GROUP BY statement can be turned off via the 'sql_group_by = FALSE' argument, or alternatively can be set to group the records by another table column.


This function is compatible with flexi auths 'Query Builder' functions.


This function can be chained with CodeIgniters query functions 'result()', 'row()' etc.

Read the Query Result documentation for further information on all the combined flexi auth and CodeIgniter functions that are available.

Return Values

Failure:FALSE

Success:object

Examples
// Example #1 : Return all users matching BOTH keywords "John" AND "Smith".
$search_query = 'John Smith';
$exact_match = TRUE;

$this->flexi_auth->search_users($search_query, $exact_match);
// Example #2 : Return all users matching EITHER keywords "John" OR "Smith".
$search_query = 'John Smith';
$exact_match = FALSE;

$this->flexi_auth->search_users($search_query, $exact_match);
// Example #3 : As example #1, but additionally defining specific columns to return,
// adding an additional SQL WHERE statement, and preventing records being grouped by the user id.
$search_query = 'John Smith';
$exact_match = FALSE;

// Read the defining SQL documentation for further information on setting SQL statements.
$sql_select = array(...);
$sql_where = array(...);
$sql_group_by = TRUE;

// Example of chaining CI's query function 'result()'.
// Read the Query Result documentation for further information on available functions.
$this->flexi_auth->search_users($search_query, $exact_match, $sql_select, $sql_where, $sql_group_by)->result();

get_unactivated_users()

Get users that have not activated their account within a set time period.


Library and Requirements

Available via the standard library.

Function Parameters
get_unactivated_users(inactive_days, sql_select, sql_where) Help
Name Data Type Required Default Description
inactive_days int Yes 28 Defines the number of days that inactive user accounts will be filtered by.
For example, defining '28' would return all users that have not activated their account within 28 days since registration.
sql_select string | array No FALSE Define the database fields returned via an SQL SELECT statement.
Read the defining SQL documentation for further information.
sql_where string | array No FALSE Set the SQL WHERE statement used to filter the database records to return.
Read the defining SQL documentation for further information.
How it Works

The function works in a similar way to the other user query functions within the library, with the exception that it applies an additional SQL WHERE statement to filter all inactive user account that registered outside of a defined number of days.

Notes

This function is compatible with flexi auths 'Query Builder' functions.


This function can be chained with CodeIgniters query functions 'result()', 'row()' etc.

Read the Query Result documentation for further information on all the combined flexi auth and CodeIgniter functions that are available.

Return Values

Failure:FALSE

Success:object

Examples
// Example #1 : Get all inactive users that registered over 14 days ago.
$inactive_days = 14;

$this->flexi_auth->get_unactivated_users($inactive_days);
// Example #2 : As example #1, but additionally defining specific columns to return and
// adding an additional SQL WHERE statement.
$inactive_days = 14;

// Read the defining SQL documentation for further information on setting SQL statements.
$sql_select = array(...);
$sql_where = array(...);

// Example of chaining CI's query function 'result()'.
// Read the Query Result documentation for further information on available functions.
$this->flexi_auth->get_unactivated_users($inactive_days, $sql_select, $sql_where)->result();

resend_activation_token()

Resend user a new activation token incase they have lost the previous one.


Library and Requirements

Available via the standard library.

Function Parameters
resend_activation_token(identity) Help
Name Data Type Required Default Description
identity string No FALSE Defines the users identity (Username and/or Email) from the user account table.
If no value is defined, the function will try to use the primary identity of the current logged in user.
How it Works

The function checks the status of the users account to confirm whether their account is inactive.

A new activation token is then set and is emailed to the user.

Return Values

Failure:FALSE | An error message will be set.

Success:TRUE | A status message will be set.

Example
$identity = 'custom_identity';

$this->flexi_auth->resend_activation_token($identity);