生成js用的字典数组
public function generateDic(){
$list = M('Dictionary') ->field('name,title') ->where("status = 1") -> order('name') -> select();
$set_list = array();
foreach($list as $k => $v)
{
$set_list[] = 'dicarray["'.$v['name'].'"]="'.$v['title'].'"';
//$set_list[$v['name']] = $v['title'] ;
}
$myjs = implode(";", $set_list).';';
echo $myjs;
return;
}
/*
php代码生成字典表数组,在js中使用
*/
public function generateDicArray(){
$Dictionary = M('Dictionary');
$where_parent = array();
$where_parent['pid']=0;
$where_parent['status']=1;
$list = $Dictionary->field('id,name,title,pid') ->where($where_parent) -> order('name') -> select();
$putout='';
foreach($list as $dic_parent){
$putout.= 'dicarray_array["'.$dic_parent['name'].'"]=';
$where_parent = array();
$where_parent['pid']=$dic_parent['id'];
$where_parent['status']=1;
$list_sub = $Dictionary->field('id,name,title,pid') ->where($where_parent)->select();
$set_list = array();
foreach($list_sub as $k => $v)
{
$set_list[] = '"'.$v['name'].'":"'.$v['title'].'"';
}
$putout .= '{'.implode(",", $set_list).'};
';
}
echo $putout;
return;
}