ESP32 Platform Documentation

UserMetaService
in package

Provides service to store user meta

Tags
example
$meta = service('user_meta');
$meta->save( 'key', 'string/json' );
$value = $meta->find( 'key' );

Table of Contents

Properties

$user  : mixed
$user_data  : mixed
$user_meta  : mixed

Methods

__construct()  : mixed
This method initializes the `User` object, retrieves the user's information, and ensures the user is valid.
find()  : mixed
Retrieve a meta value for a given user.
save()  : void
Save a user meta key-value pair.

Properties

Methods

__construct()

This method initializes the `User` object, retrieves the user's information, and ensures the user is valid.

public __construct() : mixed

If the user is not valid, the process is halted with an error message.

It also initializes the appropriate user_meta

Tags
throws
Exception

If the user data is invalid or missing, the action will be halted with an error message.

find()

Retrieve a meta value for a given user.

public find(string $name[, int|null $user_id = null ]) : mixed

This method fetches the stored value associated with a specific key (name) for the given user. If no user ID is provided, it defaults to the current user session.

Parameters
$name : string

The name of the key whose value is to be retrieved.

$user_id : int|null = null

(Optional) The ID of the user. Defaults to NULL (current user session).

Return values
mixed

The stored value associated with the specified key, or NULL if not found.

save()

Save a user meta key-value pair.

public save(string $name, string $value[, int|null $user_id = null ]) : void

Stores a value associated with a specific key. If a user ID is provided, the value is saved for that user. If no user ID is provided, the value is associated with the current user session.

Parameters
$name : string

The name under which the value will be stored.

$value : string

The value to be stored (preferably in JSON format).

$user_id : int|null = null

(Optional) The ID of the user. Defaults to NULL (current user session).


        
On this page

Search results