\Dewdrop\Fields\RowEditor\LinkField

Provide a row that can be associated with all the fields from a model in a RowEditor. This particular linker uses a field object to get the look-up value. This can be useful if you have a primary row linked in the row editor by query string and you then need to pull in a second, related row based upon a foreign key in the first.

For example, say you were writing a order management component. Your edit page would pull up the order using the "order_id" query string variable and then pull up the associated address rows using the order row's shipping_address_id and billing_address_id fields. To pull this off, you'd set up your RowEditor like this:

$this->rowEditor
    ->linkByQueryString('orders', 'order_id')
    ->linkByField('shipping_address', $orderModel->field('shipping_address_id'))
    ->linkByField('billing_address', $orderModel->field('billing_address_id'));

Note that because this linker requires the look-up field have its own row association, it requires a \Dewdrop\Db\Field, not just a \Dewdrop\Field\FieldInterface.

Summary

Methods
Properties
Constants
__construct()
link()
populateValueFromSavedRow()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$rowEditor
$field
N/A

Properties

$rowEditor

$rowEditor : \Dewdrop\Fields\RowEditor

The RowEditor this link is associated with. Used to get the field's row, if needed.

Type

\Dewdrop\Fields\RowEditor

$field

$field : \Dewdrop\Db\Field

The field that will be used to get the look-up value.

Type

\Dewdrop\Db\Field

Methods

__construct()

__construct(\Dewdrop\Fields\RowEditor  $rowEditor, \Dewdrop\Db\Field  $field) 

Provide a field that can be used when looking up the primary key value for the generated row object.

Parameters

\Dewdrop\Fields\RowEditor $rowEditor
\Dewdrop\Db\Field $field

link()

link(\Dewdrop\Db\Table  $table) : \Dewdrop\Db\Row

Provide a row that can be linked to all the fields from the supplied table. If the field has a value, we'll look up the row using the table's find() method. Otherwise, we'll create a new row. Note that an exception is throw if you attempt to use this linker with a field that doesn't itself have a row associated with it already. Often you'll link to the first row using a \Dewdrop\Fields\RowEditor\Link\QueryString rule and then string Field linker on after that.

Parameters

\Dewdrop\Db\Table $table

Throws

\Dewdrop\Fields\Exception

Returns

\Dewdrop\Db\Row

populateValueFromSavedRow()

populateValueFromSavedRow(\Dewdrop\Db\Row  $row) : \Dewdrop\Fields\RowEditor\Link\Field

Populate the primary key value from the supplied row (already saved in the RowEditor) up to the linked field in this object. For example, say you'd configured a link like this in your RowEditor:

$rowEditor->linkByField('addresses', $this->orderModel->field('address_id'));

Then, when this method was called, you'd get a row from the addresses table that had already been saved by the row editor. And, using that row, this method would set the value of the orderModel's address_id field to the primary key of the addresses row.

Parameters

\Dewdrop\Db\Row $row

Returns

\Dewdrop\Fields\RowEditor\Link\Field