northug/yii2-simplelist

模型属性的数据列表

安装: 181

依赖者: 0

建议者: 0

安全: 0

类型:yii2-extension

dev-master 2019-04-09 10:42 UTC

This package is auto-updated.

Last update: 2024-09-10 00:14:10 UTC


README

在模型中添加元标签和标题

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一

php composer.phar require --prefer-dist northug/yii2-simplelist "*"

或者在您的 composer.json 文件的 require 部分添加

"northug/yii2-simplelist": "*"

迁移

yii migrate --migrationPath=@northug/metaTags/migrations

用法

安装扩展后,只需在代码中通过以下方式使用它

MetaTagBehavior 添加到您的模型中,并进行配置。

'controllerMap' => [
    ...
    'simplelist' => [
        'class' => 'northug\simplelist\Controller',
    ]
    ...
],

在模型中

public function behaviors() {
    return [
        [
            'class' => ListBehavior::class,
            'attributes' => ['attribute'],
        ],
    ];
}

在表单中

<?= $form->field($model, 'attribute')->widget(ListWidget::class, [
        'structure' => [
            ['name' => 'code', 'title' => 'Code city', 'type' => 'text'],
            ['name' => 'phone', 'title' => 'Phone city', 'type' => 'text'],
        ],
    ]) ?>