Menu

## Options extends Ext
in package

Options.php : 64

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

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

  @example Get a list of options with custom ordering

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

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

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

### Table of Contents

add() : Options
  Add extra options to the list, in addition to any obtained from the database
inst() : Editor|Field|Join|Upload
  Static method to instantiate a new instance of a class (shorthand of 'instantiate').
instantiate() : Editor|Field|Join|Upload
  Static method to instantiate a new instance of a class.
label() : Options|array<string|int, string>
  Get / set the column(s) to use as the label value of the options
leftJoin() : self
  Set up a left join operation for the options
limit() : Options|array<string|int, string>
  Get / set the LIMIT clause to limit the number of records returned.
order() : Options|string
  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() : Options|callable
  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() : Options|string
  Get / set the database table from which to gather the options for the list.
value() : Options|string
  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() : Options|callable
  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

#### add()

Options.php : 107

Add extra options to the list, in addition to any obtained from the database

`public add(string $label[, string|null $value = null ]) : Options`

##### Parameters

$label : string

  The label to use for the option

$value : string|null = null

  Value for the option. If not given, the label will be used

##### Return values

Options —

Self for chaining

#### inst()

Ext.php : 51

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

`public static inst() : Editor|Field|Join|Upload`

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

##### Return values

Editor|Field|Join|Upload —

class @static

#### instantiate()

Ext.php : 32

Static method to instantiate a new instance of a class.

`public static instantiate() : Editor|Field|Join|Upload`

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

Editor|Field|Join|Upload —

Instantiated class @static

#### label()

Options.php : 129

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

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

##### Parameters

$_ : null|string|array<string|int, string> = null

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

##### Return values

Options|array<string|int, string> —

Self if setting for chaining, array of values if getting.

#### leftJoin()

Options.php : 153

Set up a left join operation for the options

`public leftJoin(string $table, string $field1, string $operator, string $field2) : self`

##### 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

self —

#### limit()

Options.php : 171

Get / set the LIMIT clause to limit the number of records returned.

`public limit([null|number $_ = null ]) : Options|array<string|int, string>`

##### Parameters

$_ : null|number = null

  Number of rows to limit the result to

##### Return values

Options|array<string|int, string> —

Self if setting for chaining, limit if getting.

#### order()

Options.php : 184

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([null|string $_ = null ]) : Options|string`

##### Parameters

$_ : null|string = null

  String to set, null to get current value

##### Return values

Options|string —

Self if setting for chaining, string if getting.

#### render()

Options.php : 198

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([null|callable $_ = null ]) : Options|callable`

##### Parameters

$_ : null|callable = null

  Function to set, null to get current value

##### Return values

Options|callable —

Self if setting for chaining, callable if getting.

#### table()

Options.php : 210

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

`public table([null|string $_ = null ]) : Options|string`

##### Parameters

$_ : null|string = null

  String to set, null to get current value

##### Return values

Options|string —

Self if setting for chaining, string if getting.

#### value()

Options.php : 222

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([null|string $_ = null ]) : Options|string`

##### Parameters

$_ : null|string = null

  String to set, null to get current value

##### Return values

Options|string —

Self if setting for chaining, string if getting.

#### where()

Options.php : 235

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([null|callable $_ = null ]) : Options|callable`

##### Parameters

$_ : null|callable = null

  Function to set, null to get current value

##### Return values

Options|callable —

Self if setting for chaining, callable if getting.

#### _getSet()

Ext.php : 75

Common getter / setter function for DataTables classes.

`protected _getSet(mixed &$prop, mixed $val[, mixed $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 @param mixed $val The value to set - if given as null, then we assume that the function is being used as a getter. @param boolean $array 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. @return self|mixed Class instance if setting (allowing chaining), or the value requested if getting.

$val : mixed
$array : mixed = false

##### Return values

mixed —

#### _propExists()

Ext.php : 105

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

##### Tags

private

##### Return values

bool —

true if present, false otherwise

#### _readProp()

Ext.php : 142

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

##### Tags

private

##### Return values

mixed —

The read value, or null if no value found.

#### _writeProp()

Ext.php : 186

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

##### Tags

throws
  Exception

  Information about duplicate properties

private

##### Return values

mixed —

## Search results