\Nano4\ModelsUser

User (DB row) base class, as used by our Controllers\Auth trait.

As with the Users base class, this is a minimum, and should be extended.

The user schema must have at least the following fields:

'id' The primary key, generally a SERIAL auto-incrementing integer. 'reset' A string containing a reset code, used to reset the password. 'hash' A string containing the authentication hash. 'token' A string containing a unique identifier used in the hash. 'email' A string containing the primary e-mail address for the user.

Any other fields are up to you, but those are the ones used by the Controllers\Auth trait, and thus required for the methods below.

Summary

Methods
Properties
Constants
__construct()
__set()
restore()
undo()
__get()
__isset()
__unset()
offsetExists()
offsetSet()
offsetUnset()
offsetGet()
save()
delete()
start_batch()
end_batch()
cancel_batch()
changePassword()
resetReset()
changeEmail()
$parent
$auto_save
$new_query_fields
No constants found
db_field()
$data
$table
$modified_data
$save_value
$primary_key
$aliases
$auto_generated_pk
N/A
No private methods found
No private properties found
N/A

Properties

$parent

$parent : 

Type

$auto_save

$auto_save : 

Type

$new_query_fields

$new_query_fields : 

Type

$data

$data : 

Type

$table

$table : 

Type

$modified_data

$modified_data : 

Type

$save_value

$save_value : 

Type

$primary_key

$primary_key : 

Type

$aliases

$aliases : 

Type

$auto_generated_pk

$auto_generated_pk : 

Type

Methods

__construct()

__construct(  $data,   $parent,   $table,   $primary_key = Null) 

Parameters

$data
$parent
$table
$primary_key

__set()

__set(  $field,   $value) 

Set a database field.

Unless $auto_generated_pk is set to False, this will throw an exception if you try to set the value of the primary key.

Parameters

$field
$value

restore()

restore(  $name) 

Restore the previous value (we only store one.) Does not work with auto_save turned on.

Parameters

$name

undo()

undo() 

Undo all modifications.

Does not work with auto_save turned on.

__get()

__get(  $field) 

Get a database field.

Parameters

$field

__isset()

__isset(  $name) 

See if a database field is set.

For the purposes of this method, '' is considered unset.

Parameters

$name

__unset()

__unset(  $name) 

Sets a field to null.

Parameters

$name

offsetExists()

offsetExists(  $name) 

ArrayAccess interface, alias to __isset().

Parameters

$name

offsetSet()

offsetSet(  $name,   $value) 

ArrayAccess interface, alias to __set().

Parameters

$name
$value

offsetUnset()

offsetUnset(  $name) 

ArrayAccess interface, alias to __unset().

Parameters

$name

offsetGet()

offsetGet(  $name) 

ArrayAccess interface, alias to __get().

Parameters

$name

save()

save() 

Save our data back to the database.

If the primary key is set, and has not been modified, this will update the existing record with the new data.

If the primary key has not been set, or has been modified, this will insert a new record into the database, and in the case of auto-generated primary keys, update our primary key field to point to the new record.

delete()

delete() 

Delete this item from the database.

start_batch()

start_batch() 

Start a batch operation.

We disable the 'auto_save' feature, saving its value for later.

end_batch()

end_batch() 

Finish a batch operation.

We restore the auto_save value, and if it was true, save the data.

cancel_batch()

cancel_batch() 

Cancel a batch operation.

We run $this->undo() and then restore the auto_save value.

changePassword()

changePassword(String  $newpass, Bool  $autosave = True) 

Change our password.

Parameters

String $newpass

The new password

Bool $autosave

Save automatically (default True)

resetReset()

resetReset(Bool  $autosave = True) : String

Reset our reset code to a unique value.

Parameters

Bool $autosave

Save automatically (default True)

Returns

String —

The new reset code is returned.

changeEmail()

changeEmail(String  $newemail, Bool  $autosave = True) : Bool

Change our e-mail address, ensuring that it is unique.

This is only required in a user model where every user must have a unique e-mail address, such is the case if the e-mail address is used as a login field.

Parameters

String $newemail

The new email address.

Bool $autosave

Save automatically (default True)

Returns

Bool —

False means e-mail address already in use. True means we updated successfully.

db_field()

db_field(  $name,   $strict = True) 

Look for a field

If the field exists in the database, it's returned unchanged.

If an alias exists, the alias target field will be returned.

If neither exists, and the field is not the primary key, an exception will be thrown.

Parameters

$name
$strict