Oihana PHP

ListModel

Interface for models that provide a list of documents or items.

This interface defines a method to retrieve all documents from a model as an array. It is suitable for cases where the dataset is small enough to be loaded entirely into memory.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

list()  : array<string|int, mixed>
Returns a collection of items from the model.

Methods

list()

Returns a collection of items from the model.

public list([array<string|int, mixed> $init = [] ]) : array<string|int, mixed>

Retrieves all documents as an array. For large datasets, consider using a streaming approach (e.g., StreamModel) to avoid high memory usage.

Parameters
$init : array<string|int, mixed> = []

Operation options scoping the result set, typically conditions with their binds, a sort clause and pagination bounds (offset/limit). An empty array lists every document.

Tags
example
use oihana\models\interfaces\ListModel;

class UserModel implements ListModel
{
    public function list( array $init = [] ) : array
    {
        return $this->store->query( $init[ 'conditions' ] ?? null, $init[ 'sort' ] ?? null ) ;
    }
}

$model = new UserModel() ;

$all    = $model->list() ;
$active = $model->list( [ 'conditions' => 'doc.active == true', 'sort' => 'name' ] ) ;
Return values
array<string|int, mixed>

An array of documents or items. The structure and type of each item depend on the model implementation.

On this page

Search results