yii\widgets\ActiveForm::field PHP Method

field() public method

A form field is associated with a model and an attribute. It contains a label, an input and an error message and use them to interact with end users to collect their inputs for the attribute.
See also: fieldConfig
public field ( Model $model, string $attribute, array $options = [] ) : ActiveField
$model yii\base\Model the data model.
$attribute string the attribute name or expression. See [[Html::getAttributeName()]] for the format about attribute expression.
$options array the additional configurations for the field object. These are properties of [[ActiveField]] or a subclass, depending on the value of [[fieldClass]].
return ActiveField the created ActiveField object.
    public function field($model, $attribute, $options = [])
    {
        $config = $this->fieldConfig;
        if ($config instanceof \Closure) {
            $config = call_user_func($config, $model, $attribute);
        }
        if (!isset($config['class'])) {
            $config['class'] = $this->fieldClass;
        }
        return Yii::createObject(ArrayHelper::merge($config, $options, ['model' => $model, 'attribute' => $attribute, 'form' => $this]));
    }

Usage Example

Example #1
5
 public function renderConfigForm(ActiveForm $form)
 {
     echo $form->fieldSet(\Yii::t('skeeks/cms', 'Main'));
     echo $form->field($this, 'enabled')->checkbox();
     echo $form->fieldCheckboxBoolean($this, 'isOpen');
     echo $form->field($this, 'enableFancyboxWindow')->widget(\skeeks\widget\chosen\Chosen::className(), ['items' => \Yii::$app->formatter->booleanFormat]);
     echo $form->fieldRadioListBoolean($this, 'editWidgets');
     echo $form->fieldRadioListBoolean($this, 'editViewFiles');
     echo $form->field($this, 'infoblockEditBorderColor')->widget(\skeeks\cms\widgets\ColorInput::className());
     echo $form->fieldSetEnd();
     echo $form->fieldSet(\Yii::t('skeeks/cms', 'Access'));
     echo \skeeks\cms\widgets\rbac\PermissionForRoles::widget(['permissionName' => \skeeks\cms\rbac\CmsManager::PERMISSION_CONTROLL_PANEL, 'label' => 'Доступ к панеле разрешен']);
     echo $form->fieldSetEnd();
 }
All Usage Examples Of yii\widgets\ActiveForm::field