Editor PHP 2.3.2

SearchBuilderOptions extends Ext
in package

The Options class provides a convenient method of specifying where Editor should get the list of options for a `select`, `radio` or `checkbox` field.

This is normally from a table that is left joined to the main table being edited, and a list of the values available from the joined table is shown to the end user to let them select from.

Options instances are used with the Field->options() method.

Tags
example

Get a list of options from the sites table

(new Field( 'users.site' ))
    ->options( (new Options())
        ->table( 'sites' )
        ->value( 'id' )
        ->label( 'name' )
    )
example

Get a list of options with custom ordering

(new Field( 'users.site' ))
    ->options( (new Options())
        ->table( 'sites' )
        ->value( 'id' )
        ->label( 'name' )
        ->order( 'name DESC' )
    )
example

Get a list of options showing the id and name in the label

(new Field( 'users.site' ))
    ->options( (new Options())
        ->table( 'sites' )
        ->value( 'id' )
        ->label( [ 'name', 'id' ] )
        ->render( function ( $row ) {
          return $row['name'].' ('.$row['id'].')';
        } )
    )

Table of Contents

Methods

inst()  : static
Static method to instantiate a new instance of a class (shorthand of 'instantiate').
instantiate()  : static
Static method to instantiate a new instance of a class.
label()  : mixed
Get / set the column(s) to use as the label value of the options.
leftJoin()  : $this
Get / set the array values used for a leftJoin condition if it is to be applied to the query to get the options.
order()  : mixed
Get / set the ORDER BY clause to use in the SQL. If this option is not provided the ordering will be based on the rendered output, either numerically or alphabetically based on the data returned by the renderer.
render()  : mixed
Get / set the label renderer. The renderer can be used to combine multiple database columns into a single string that is shown as the label to the end user in the list of options.
table()  : mixed
Get / set the database table from which to gather the options for the list.
value()  : mixed
Get / set the column name to use for the value in the options list. This would normally be the primary key for the table.
where()  : mixed
Get / set the method to use for a WHERE condition if it is to be applied to the query to get the options.
_getSet()  : mixed
Common getter / setter function for DataTables classes.
_propExists()  : bool
Determine if a property is available in a data set (allowing `null` to be a valid value).
_readProp()  : mixed
Read a value from a data structure, using Javascript dotted object notation. This is the inverse of the `_writeProp` method and provides the same support, matching DataTables' ability to read nested JSON data objects.
_writeProp()  : mixed
Write the field's value to an array structure, using Javascript dotted object notation to indicate JSON data structure. For example `name.first` gives the data structure: `name: { first: ... }`. This matches DataTables own ability to do this on the client-side, although this doesn't implement implement quite such a complex structure (no array / function support).

Methods

inst()

Static method to instantiate a new instance of a class (shorthand of 'instantiate').

public static inst() : static

This method performs exactly the same actions as the 'instantiate' static method, but is simply shorter and easier to type!

Return values
static

class

instantiate()

Static method to instantiate a new instance of a class.

public static instantiate() : static

A factory method that will create a new instance of the class that has extended 'Ext'. This allows classes to be instantiated and then chained - which otherwise isn't available until PHP 5.4. If using PHP 5.4 or later, simply create a 'new' instance of the target class and chain methods as normal.

Return values
static

Instantiated class

label()

Get / set the column(s) to use as the label value of the options.

public label([string|array<string|int, string>|null $_ = null ]) : mixed
Parameters
$_ : string|array<string|int, string>|null = null

null to get the current value, string or array to get.

leftJoin()

Get / set the array values used for a leftJoin condition if it is to be applied to the query to get the options.

public leftJoin(string $table, string $field1, string $operator, string $field2) : $this
Parameters
$table : string

to get the information from

$field1 : string

the first field to get the information from

$operator : string

the operation to perform on the two fields

$field2 : string

the second field to get the information from

Return values
$this

order()

Get / set the ORDER BY clause to use in the SQL. If this option is not provided the ordering will be based on the rendered output, either numerically or alphabetically based on the data returned by the renderer.

public order([string|null $_ = null ]) : mixed
Parameters
$_ : string|null = null

String to set, null to get current value

render()

Get / set the label renderer. The renderer can be used to combine multiple database columns into a single string that is shown as the label to the end user in the list of options.

public render([mixed $_ = null ]) : mixed
Parameters
$_ : mixed = null

table()

Get / set the database table from which to gather the options for the list.

public table([string|null $_ = null ]) : mixed
Parameters
$_ : string|null = null

String to set, null to get current value

value()

Get / set the column name to use for the value in the options list. This would normally be the primary key for the table.

public value([string|null $_ = null ]) : mixed
Parameters
$_ : string|null = null

String to set, null to get current value

where()

Get / set the method to use for a WHERE condition if it is to be applied to the query to get the options.

public where([mixed $_ = null ]) : mixed
Parameters
$_ : mixed = null

_getSet()

Common getter / setter function for DataTables classes.

protected _getSet(mixed &$prop, mixed $val[, bool $array = false ]) : mixed

This getter / setter method makes building getter / setting methods easier, by abstracting everything to a single function call.

Parameters
$prop : mixed

The property to set

$val : mixed

The value to set - if given as null, then we assume that the function is being used as a getter.

$array : bool = false

Treat the target property as an array or not (default false). If used as an array, then values passed in are added to the $prop array.

_propExists()

Determine if a property is available in a data set (allowing `null` to be a valid value).

protected _propExists(string $name, array<string|int, mixed> $data) : bool
Parameters
$name : string

Javascript dotted object name to write to

$data : array<string|int, mixed>

Data source array to read from

Return values
bool

true if present, false otherwise

_readProp()

Read a value from a data structure, using Javascript dotted object notation. This is the inverse of the `_writeProp` method and provides the same support, matching DataTables' ability to read nested JSON data objects.

protected _readProp(string $name, array<string|int, mixed> $data) : mixed
Parameters
$name : string

Javascript dotted object name to write to

$data : array<string|int, mixed>

Data source array to read from

Return values
mixed

The read value, or null if no value found.

_writeProp()

Write the field's value to an array structure, using Javascript dotted object notation to indicate JSON data structure. For example `name.first` gives the data structure: `name: { first: ... }`. This matches DataTables own ability to do this on the client-side, although this doesn't implement implement quite such a complex structure (no array / function support).

protected _writeProp(array<string|int, mixed> &$out, string $name, mixed $value) : mixed
Parameters
$out : array<string|int, mixed>

Array to write the data to

$name : string

Javascript dotted object name to write to

$value : mixed

Value to write


        
On this page

Search results