多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
**setExtraItems ($extra_items)** 这个方法与addFormItem是一个系列的,此方法用于批量添加已经提前按规范构造好的数组来添加表单项目(具体格式可以参考第三方登录插件的config.php),比如后台的插件配置就是实用此方法,为什么要使用此方法,因为像后台插件这种,每个插件的配置字段都是不一样的,都存储在数据库里或者文件系统里,所以你没办法用addFormItem去一个个去添加,只能用setExtraItems这种办法一次性把数据传递给FormBuilder,这种办法不但支持一维TAB还支持多TAB表单,与SetTabNav实际不一样,这个TAB是在同一个页面里的切换,而SetTabNav实际上是一个链接跳转了而已。 > 当然了setExtraItems和addFormItem是支持一起同时使用的。 **参数** @param $extra_items 标单项数组(格式可以第三方登录插件的config.php) 类似下面这样: ~~~ array( 'title'=>'开启同步登录:', 'type'=>'checkbox', 'options'=>array( 'Weixin'=>'微信', 'Qq'=>'QQ', 'Sina'=>'新浪', 'Renren'=>'人人', 'Github'=>'Github', ), ), 'meta'=>array( 'title'=>'接口验证代码:', 'type'=>'textarea', 'value'=>'', 'tip'=>'需要在Meta标签中写入验证信息时,拷贝代码到这里。' ), 'group'=>array( 'type'=>'group', 'options'=>array( 'Wexin'=>array( 'title'=>'微信配置', 'options'=>array( 'WeixinKey'=>array( 'title'=>'微信APPKEY:', 'type'=>'text', 'value'=>'', 'tip'=>'申请地址:http://open.weixin.qq.com/', ), 'WeixinSecret'=>array( 'title'=>'微信APPSECRET:', 'type'=>'text', 'value'=>'', 'tip'=>'申请地址:http://open.weixin.qq.com/', ) ) ), 'Qq'=>array( 'title'=>'QQ配置', 'options'=>array( 'QqKey'=>array( 'title'=>'QQ互联APPKEY:', 'type'=>'text', 'value'=>'', 'tip'=>'申请地址:http://connect.qq.com', ), 'QqSecret'=>array( 'title'=>'QQ互联APPSECRET:', 'type'=>'text', 'value'=>'', 'tip'=>'申请地址:http://connect.qq.com', ) ), ), 'Sina'=>array( 'title'=>'新浪配置', 'options'=>array( 'SinaKey'=>array( 'title'=>'新浪APPKEY:', 'type'=>'text', 'value'=>'', 'tip'=>'申请地址:http://open.weibo.com/', ), 'SinaSecret'=>array( 'title'=>'新浪APPSECRET:', 'type'=>'text', 'value'=>'', 'tip'=>'申请地址:http://open.weibo.com/', ) ), ), 'Renren'=>array( 'title'=>'人人配置', 'options'=>array( 'RenrenKey'=>array( 'title'=>'人人APPKEY:', 'type'=>'text', 'value'=>'', 'tip'=>'申请地址:http://dev.renren.com/', ), 'RenrenSecret'=>array( 'title'=>'人人APPSECRET:', 'type'=>'text', 'value'=>'', 'tip'=>'申请地址:http://dev.renren.com/', ) ) ), 'Github'=>array( 'title'=>'Github配置', 'options'=>array( 'GithubKey'=>array( 'title'=>'GithubAPPKEY:', 'type'=>'text', 'value'=>'', 'tip'=>'申请地址:https://github.com/settings/applications', ), 'GithubSecret'=>array( 'title'=>'GithubAPPSECRET:', 'type'=>'text', 'value'=>'', 'tip'=>'申请地址:https://github.com/settings/applications', ) ) ) ) ) ); ~~~ **用法示例** ~~~ $db_config = $addon['config']; $addon['config'] = include $data->config_file; if ($db_config) { $db_config = json_decode($db_config, true); foreach ($addon['config'] as $key => $value) { if ($value['type'] != 'group') { $addon['config'][$key]['value'] = $db_config[$key]; } else { foreach ($value['options'] as $gourp => $options) { foreach ($options['options'] as $gkey => $value) { $addon['config'][$key]['options'][$gourp]['options'][$gkey]['value'] = $db_config[$gkey]; } } } } } // 构造表单名 foreach ($addon['config'] as $key => $val) { if ($val['type'] == 'group') { foreach ($val['options'] as $key2 => $val2) { foreach ($val2['options'] as $key3 => $val3) { $addon['config'][$key]['options'][$key2]['options'][$key3]['name'] = 'config['.$key3.']'; } } } else { $addon['config'][$key]['name'] = 'config['.$key.']'; } } $this->assign('data', $addon); $this->assign('form_items', $addon['config']); if ($addon['custom_config']) { $this->assign('custom_config', $this->fetch($addon['addon_path'].$addon['custom_config'])); $this->display($addon['addon_path'].$addon['custom_config']); } else { //使用FormBuilder快速建立表单页面。 $builder = new \Common\Builder\FormBuilder(); $builder->setMetaTitle('插件设置') //设置页面标题 ->setPostUrl(U('config')) //设置表单提交地址 ->addFormItem('id', 'hidden', 'ID', 'ID') ->setExtraItems($addon['config']) //直接设置表单数据 ->setFormData($addon) ->display(); } ~~~