Octobercms:我如何将转发器字段设为json,因为我正在将该转发器字段创建到其他插件中 [英] Octobercms: How can I make a repeater field jsonable because I am creating this repeater field into a different plugin

查看:120
本文介绍了Octobercms:我如何将转发器字段设为json,因为我正在将该转发器字段创建到其他插件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使转发器字段 jsonable ,因为我正在将该转发器字段创建到其他插件中,并且已经创建了自己的插件. 例如:我想在 rainlab.user 插件模型中添加一个Repeater字段,但是我想通过自己的插件进行此操作,因此不会更新 rainlab.user 插件影响我的工作. 谢谢

How can I make a repeater field jsonable because I am creating this repeater field into a different plugin and I have created my own plugin. for example: I want to add a repeater field in rainlab.user plugin model but I want to do this by my own plugin so updates on rainlab.user plugin won't affect my work. Thanks

推荐答案

您应该阅读有关扩展插件.

1)首先在您的自定义plugin.php中注册事件-

1) First register the events in your custom plugin.php - Example

2)将相关字段添加到您的迁移文件中-

2) Add the related fields to your migration file - Example - Make sure the field type is set to json or text : $table->json('field_name')->nullable();

假设您要在用户模型中添加Dogs中继器字段;

Let's say you want to add a Dogs repeater field to the User Model ;

public function boot()
{

    UserModel::extend(function($model)
    {
        $model->addJsonable([
            'dogs',
        ]);
    });

    UsersController::extendFormFields(function($form, $model, $context){

        if (!$model instanceof UserModel) {
            return;
        }

        $form->addTabFields([
            'dogs' => [
                'label'      => 'My Dogs',
                'type'       => 'repeater',
                'form'       => [
                    'fields' => [
                        'breed' => [
                            'label' => 'Breed',
                            'type' => 'dropdown',
                            'options' => [
                                'labrador' => "Labrador",
                                'cocker'   => "Cocker Spaniel"
                            ]
                        ],
                        'name' => [
                            'label' => 'Name',
                            'type' => 'text',
                        ]
                    ],
                ],
            ],
        ]);

    });

}

这篇关于Octobercms:我如何将转发器字段设为json,因为我正在将该转发器字段创建到其他插件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆