Skip to content
SuperScript edited this page Aug 16, 2014 · 4 revisions
Model Extends Table Path
Users_Model Plain_Model users /application/models/users_model.php

Loading the model

$this->load->model('users_model', 'users');

Properties

Property Visibility Default Value Description
$sort Public user_id DESC The default sort direction for reads.

Methods

__construct - Public

Called automatically which in turn calls the parent constructor and sets the model $data_types properties.


create - Public

Used to create new records in the users table.

Arguments (Overall)

Variable Type Default Required Description
$options array array() Yes An associative array that contains the column names and the values for the record to be created. Array keys are the column names for each value.
$options['email'] string N/A Yes The email address for the user.
$options['password'] string N/A Yes The password for the user. The method will encrypt it for you.

Example

$this->load->model('users_model', 'users');
$user = $this->users->create(array('email' => $name, 'password' => $password));

// If user was created
if (isset($user->user_id)) {
    // Good to go
}

// Some sort of validation error
elseif (isset($user['errors']) {
    // Validation errors were found
}

// Some sort of database write error, check logs
else {
    // will return false
}