**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();
}
~~~
- 序言
- 基礎
- 安裝
- 開發規范
- 目錄結構
- 表單生成器
- setMetaTitle
- setTabNav
- setExtraItems
- setPostUrl
- addFormItem
- setFormData
- setExtraHtml
- setAjaxSubmit
- setTemplate
- 表格生成器
- setMetaTitle
- addTopButton
- addTableColumn
- setTableDataList
- setTableDataListKey
- addRightButton
- setTableDataPage
- setSearch
- setTabNav
- addSearchItem
- alterTableData
- setExtraHtml
- setTemplate
- 公共函數
- 后臺管理
- 系統功能
- 系統設置
- 導航管理
- 幻燈管理
- 配置管理
- 上傳管理
- 用戶權限
- 用戶管理
- 管理員管理
- 用戶組管理
- 擴展中心
- 功能模塊
- 插件管理
- 模塊
- opencmf.php
- 目錄結構
- 開發規范
- 插件
- 系統鉤子列表
- 插件開發
- 主題
- 新建主題
- 模板變量
- 模板標簽
- 附錄
- 網站配置
- 常見問題
- 更新日志
- 關于零云