PHP code example of ceroot / think-modelinfo

1. Go to this page and download the library: Download ceroot/think-modelinfo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ceroot / think-modelinfo example snippets


    $data = [
        //default 默认配置(action方法名称做为下标 action没有配置的取default, defaul定义了的在action会继承和可覆盖)
        'default'=>[
            //表单提交地址
            'url' => 'Config/updates',
            //操作方法(方法不存在的时候起作用)
            'action'=>'Config/index',
            //特殊字符串替换用于列表定义解析
            'replace_string' => [['[DELETE]','[EDIT]'],['delete?ids=[id]','edit?id=[id]']],
            //按钮组 用于模版的显示
            'button'     => [
                ['title'=>'新增','url'=>'add','icon'=>'iconfont icon-xinzeng','class'=>'list_add btn-success','ExtraHTML'=>''],
                ['title'=>'删除','url'=>'del','icon'=>'iconfont icon-shanchu','class'=>'btn-danger ajax-post confirm','ExtraHTML'=>'target-form="ids"'],
                ['title'=>'排序','url'=>'sort','icon'=>'iconfont icon-paixu','class'=>'btn-info list_sort','ExtraHTML'=>'']
            ],
            //表名
            'name' => 'config',
            //主键
            'pk' => 'id',
            //列表定义
            'list_grid'  => 'id:ID;name:名称:[EDIT];title:标题;update_time:最后更新;group|get_config_group:分组;type|get_config_type:类型;id:操作:[EDIT]|编辑,del?id=[id]|删除',
            //列表头即列表定义后解析的规则  由系统根据list_grid列表定义完成
            'list_field' => [],
            //验证字段属性信息 由系统完成 在fields设置
            'validate' => [],
            //自由组合的搜索字段  ['字段'=>'标题'] 为空取列表定义的
            'search_list'=> [
            	["name" =>"status","title" => "数据状态", "exp" => "eq","value" => "1" ,"type" => "select","extra" => "-1:假删除,0:禁用,1:启用,2:审核"]
                ], 
            //固定搜索条件
            'search_fixed' => [
            	["name" => "category_id", "exp" => "eq" ,"value" =>":[cate_id]"]
            ], 
            //表单显示分组
            'field_group'=>'1:基础',
            //表单显示排序
            "fields"=>[
                '1'=>[
                    ['name'=>'id','title'=>'UID','type'=>'string','remark'=>'','is_show'=>4],
                    ['name'=>'name','title'=>'配置标识','type'=>'string','remark'=>'用于C函数调用,只能使用英文且不能重复','is_show'=>1],
                    ['name'=>'title','title'=>'配置标题','type'=>'string','remark'=>'用于后台显示的配置标题','is_show'=>1],
                    ['name'=>'sort','title'=>'排序','type'=>'string','remark'=>'用于分组显示的顺序','is_show'=>1],
                    ['name'=>'type','title'=>'配置类型','type'=>'select','extra'=>':config_type_list()','value'=>'','remark'=>'系统会根据不同类型解析配置值','is_show'=>1],
                    ['name'=>'group','title'=>'配置分组','type'=>'select','extra'=>':config_group_list()','value'=>'','remark'=>'配置分组 用于批量设置 不分组则不会显示在系统设置中','is_show'=>1],
                    ['name'=>'value','title'=>'配置值','type'=>'textarea','remark'=>'配置值','is_show'=>1],
                    ['name'=>'extra','title'=>'配置项','type'=>'textarea','remark'=>'如果是枚举型 需要配置该项','is_show'=>1],
                    ['name'=>'remark','title'=>'说明','type'=>'textarea','remark'=>'配置详细说明','is_show'=>1],
                ]
            ],
            //列表模板
            'template_list'=>'mould/list',
            //新增模板
            'template_add'=>'mould/add',
            //编辑模板
            'template_edit'=>'mould/edit',
            //当前模版(使用以上3种模版配置请设置为false)
            'template'=>false,
            //列表数据大小
             'list_row'=>'10',
        ],
        'group'=>[
            'url' => 'Config/save',
        ],
        'add'=>[
            'meta_title' => '新增配置',
        ],
        'edit'=>[
            'meta_title' => '编辑配置',
        ]
    ];

modelinfo();

modelinfo()->getList($data);

modelinfo()->getAdd($data);

modelinfo()->getEdit($data);