Will automatically generate a for attribute if one is not provided.
### Options
- for - Set the for attribute, if its not defined the for attribute
will be generated from the $fieldName parameter using
FormHelper::_domId().
Examples:
The text and for attribute are generated off of the fieldname
echo $this->Form->label('published');
Custom text:
echo $this->Form->label('published', 'Publish');
Custom attributes:
echo $this->Form->label('published', 'Publish', [
'for' => 'post-publish'
]);
Nesting an input tag:
echo $this->Form->label('published', 'Publish', [
'for' => 'published',
'input' => $this->text('published'),
]);
If you want to nest inputs in the labels, you will need to modify the default templates.
public label ( string $fieldName, string | null $text = null, array $options = [] ) : string | ||
$fieldName | string | This should be "modelname.fieldname" |
$text | string | null | Text that will appear in the label field. If $text is left undefined the text will be inflected from the fieldName. |
$options | array | An array of HTML attributes. |
Результат | string | The formatted LABEL element |