# Admin應用公共函數
位于?`/Application/Admin/Common/function.php`?中,供后臺調用,如果需要,您可以搜索后臺調用的位置了解具體作用.
## get_list_field($data, $grid,$model)
說明:解析列表定義規則
## get_model_by_id($id)
說明:根據模型id獲取模型名稱
## get_attribute_type($type='')
說明:獲取模型字段屬性類型信息
## get_status_title($status = null)
說明:獲取對應狀態的文字信息
參數 int $status
返回值 string 狀態文字 ,false 未獲取到
源碼:
~~~
function get_status_title($status = null){
if(!isset($status)){
return false;
}
switch ($status){
case -1 : return '已刪除'; break;
case 0 : return '禁用'; break;
case 1 : return '正常'; break;
case 2 : return '待審核'; break;
default : return false; break;
}
}
~~~
## show_status_op($status)
說明:獲取數據狀態對應的操作文字
源碼:
~~~
function show_status_op($status) {
switch ($status){
case 0 : return '啟用'; break;
case 1 : return '禁用'; break;
case 2 : return '審核'; break;
default : return false; break;
}
}
~~~
## get_document_type($type = null)
說明:獲取文檔的類型文字
參數 string $type
返回值 string 狀態文字 ,false 未獲取到
源碼
~~~
function get_document_type($type = null){
if(!isset($type)){
return false;
}
switch ($type){
case 1 : return '目錄'; break;
case 2 : return '主題'; break;
case 3 : return '段落'; break;
default : return false; break;
}
}
~~~
## get_config_type($type=0)
說明:
獲取配置的類型
參數 string $type 配置類型
返回值 string
源碼:
~~~
function get_config_type($type=0){
$list = C('CONFIG_TYPE_LIST');
return $list[$type];
}
~~~
## get_config_group($group=0)
說明:
獲取配置的分組
參數 string $group 配置分組
返回值 string
源碼:
~~~
function get_config_group($group=0){
$list = C('CONFIG_GROUP_LIST');
return $list[$group];
}
~~~
## int_to_string(&$data,$map=array('status'=>array(1=>'正常',-1=>'刪除',0=>'禁用',2=>'未審核',3=>'草稿')))
說明: 對select返回的數組進行整數映射轉換,默認轉換 status 字段,轉換結果使用status_text保存.
參數 array $map 字段值與轉換后的文字的映射關系
~~~
array(
'字段名1'=>array(值與文字映射關系數組),
'字段名2'=>array(值與文字映射關系數組),
......
)
~~~
返回值 array 示例:
~~~
array(
array('id'=>1,'title'=>'標題','status'=>'1','status_text'=>'正常')
array('id'=>2,'title'=>'標題','status'=>'0','status_text'=>'禁用')
......
)
~~~
## extra_menu($extra_menu,&$base_menu)
說明:動態擴展左側菜單,調用位置:View/Public/base.html
## get_parent_category($cid)
說明:獲取參數的所有父級分類
參數 int $cid 分類id
返回值 array 參數分類和父類的信息集合
## check_verify($code, $id = 1)
說明:檢測驗證碼是否正確
參數 integer $code 驗證碼
返回值 boolean 檢測結果
## get_type_bycate($id = null)
說明:獲取分類綁定的文檔類型
參數 int $id
返回值 array 文檔綁定的文檔類型數組
## get_cate($cate_id = null)
說明:根據分類id獲取分類的title
參數 int $cate_id
## parse_config_attr($string)
說明:解析枚舉類型配置值 格式 a:名稱1,b:名稱2
返回:解析后的枚舉配置數組
## get_subdocument_count($id=0)
說明:獲取文檔的子文檔統計數
## get_action($id = null, $field = null)
說明:
獲取行為數據
參數 string $id 行為id
參數 string $field 需要獲取的字段
源碼:
~~~
function get_action($id = null, $field = null){
if(empty($id) && !is_numeric($id)){
return false;
}
$list = S('action_list');
if(empty($list[$id])){
$map = array('status'=>array('gt', -1), 'id'=>$id);
$list[$id] = M('Action')->where($map)->field(true)->find();
}
return empty($field) ? $list[$id] : $list[$id][$field];
}
~~~
## get_document_field($value = null, $condition = 'id', $field = null)
說明:
根據條件字段獲取數據
參數 mixed $value 條件,可用常量或者數組
參數 string $condition 條件字段
參數 string $field 需要返回的字段,不傳則返回整個數據
源碼:
~~~
function get_document_field($value = null, $condition = 'id', $field = null){
if(empty($value)){
return false;
}
//拼接參數
$map[$condition] = $value;
$info = M('Model')->where($map);
if(empty($field)){
$info = $info->field(true)->find();
}else{
$info = $info->getField($field);
}
return $info;
}
~~~
## get_action_type($type, $all = false)
說明:獲取行為類型
參數 intger $type 類型
參數 bool $all 是否返回全部類型
源碼:
~~~
function get_action_type($type, $all = false){
$list = array(
1=>'系統',
2=>'用戶',
);
if($all){
return $list;
}
return $list[$type];
}
~~~