您好,欢迎访问一九零五行业门户网

无限归来之超级警察 php 无限级缓存的类的扩展

复制代码 代码如下:
db = $db;
$this->tempcode[] = idstr} from {$this->tablename} where
{$this->pidstr}='{$this->pid}' and {$this->where} ;
//exit($sql);
$result = $this->db->select($sql);
$temp = array();
foreach ($result as $r)
{
$temp[]=$r[{$this->idstr}];
}
$this->tempcode[] = \${$this->createarrayname}['root']='.implode(',',$temp).';;
//print_r($temp);
return $temp;
}
//取得子id
function getchildren($pid)
{
$sql = select {$this->idstr} from {$this->tablename} where
{$this->pidstr}='{$pid}' and {$this->where} ;
$result = $this->db->select($sql);
$temp = array();
foreach ($result as $r)
{
$temp[]=$r[{$this->idstr}];
}
return $temp;
}
//取得夫id
function getparent($cid)
{
$sql = select {$this->pidstr} from {$this->tablename} where
{$this->idstr}='{$cid}' and {$this->where} ;
$result = $this->db->select($sql);
//print_r($result);exit();
return $result[0][{$this->pidstr}];
}
//取得上级的id
function getpidstr($cid,$pidstr=)
{
$pid=$this->getparent($cid);
$temp = array();
while ($pid!=$this->pid && !emptyempty($pid)) {
$temp[] = $pid;
$pid=$this->getparent($pid);
}
//print_r($temp);
return implode(',',$temp);
}
//取得深度
function getdepth($cid,$depth=0)
{
$pid=$this->getparent($cid);
$depth++;
if( $pid != $this->pid && !emptyempty($pid))
$depth = $this->getdepth($pid,$depth);
return $depth;
}
//建立文件
function make()
{
if(emptyempty($this->createfilename))
$this->createfilename = {$this->createarrayname}.data.php;
$rootarr = $this->getrootid();
$selectf = {$this->idstr},{$this->title},{$this->pidstr};
foreach ($this->appendarr as $app)
{
if(emptyempty($app)) continue;
$selectf .=,{$app};
}
$sql = select {$selectf} from {$this->tablename} where
{$this->where};
$result = $this->db->select($sql);
for ($i=0;$i{
//id值
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['id']='{$result[$i][{$this->idstr}]}';;
//标题
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['title']='{$result[$i][{$this->title}]}';;
//父id
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['pid']='{$result[$i][{$this->pidstr}]}';;
//子id
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['cid']='.implode(',',$this->getchildren($result[$i][$this->idstr])).';;
//目录深度
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['depth']='.$this->getdepth($result[$i][$this->idstr]).';;
//父id的id串
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['pstr']='.$this->getpidstr($result[$i][$this->idstr]).';;
//添加的附加属性
foreach ($this->appendarr as $app)
{
if(emptyempty($app)) continue;
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['{$app}']='{$result[$i][{$app}]}';;
}
}
$this->tempcode[] = return \${$this->createarrayname};;
$this->tempcode[] = ?>;
//$content = implode(\n,$this->tempcode);
//print_r($this->tempcode);
$content = implode(\n,$this->tempcode);
//建立文件
$fio=factory::getbaseclass('fileio');
if($this->is_utf8) $content = \xef\xbb\xbf.$content;
$fio->writefile($this->createfilename,$content);
return $content ;
}
}
//加载的文件就是为了,数据库连接
//需要数据库有 select 方法
/*
include_once(dirname(dirname(__file__))./config/config.inc.php);
include_once(classes_path.factryobject.class.php);
$db = factryobject::getdb('indexpush');
$c = new treecache($db);
$c->make();
//exit();
//做分析
include_once(treecache.data.php);
$treecache=isset($treecache) ? $treecache : array();
$rootstr = isset($treecache['root']) ? $treecache['root'] : ;
echo parsetree($treecache,$rootstr);
function parsetree($treecache,$rootstr)
{
$tempstr = ;
$temp = explode(',',$rootstr);
foreach ($temp as $cid)
{
$info = $treecache[$cid];
$cidstr = $info['cid'];
$tempstr .= str_repeat('-',($info['depth']-1)*3);
$tempstr.=$info['title'];
if(empty($info['pid']))
{
//附加操作
}
$tempstr .=
;
if(!empty($info['cid']))
$tempstr .=parsetree($treecache,$info['cid']);
}
return $tempstr;
}
*/
?>
db = $db;
$this->tempcode[] = idstr} from {$this->tablename} where
{$this->pidstr}='{$this->pid}' and {$this->where} ;
//exit($sql);
$result = $this->db->select($sql);
$temp = array();
foreach ($result as $r)
{
$temp[]=$r[{$this->idstr}];
}
$this->tempcode[] = \${$this->createarrayname}['root']='.implode(',',$temp).';;
//print_r($temp);
return $temp;
}
//取得子id
function getchildren($pid)
{
$sql = select {$this->idstr} from {$this->tablename} where
{$this->pidstr}='{$pid}' and {$this->where} ;
$result = $this->db->select($sql);
$temp = array();
foreach ($result as $r)
{
$temp[]=$r[{$this->idstr}];
}
return $temp;
}
//取得夫id
function getparent($cid)
{
$sql = select {$this->pidstr} from {$this->tablename} where
{$this->idstr}='{$cid}' and {$this->where} ;
$result = $this->db->select($sql);
//print_r($result);exit();
return $result[0][{$this->pidstr}];
}
//取得上级的id
function getpidstr($cid,$pidstr=)
{
$pid=$this->getparent($cid);
$temp = array();
while ($pid!=$this->pid && !empty($pid)) {
$temp[] = $pid;
$pid=$this->getparent($pid);
}
//print_r($temp);
return implode(',',$temp);
}
//取得深度
function getdepth($cid,$depth=0)
{
$pid=$this->getparent($cid);
$depth++;
if( $pid != $this->pid && !empty($pid))
$depth = $this->getdepth($pid,$depth);
return $depth;
}
//建立文件
function make()
{
if(empty($this->createfilename))
$this->createfilename = {$this->createarrayname}.data.php;
$rootarr = $this->getrootid();
$selectf = {$this->idstr},{$this->title},{$this->pidstr};
foreach ($this->appendarr as $app)
{
if(empty($app)) continue;
$selectf .=,{$app};
}
$sql = select {$selectf} from {$this->tablename} where
{$this->where};
$result = $this->db->select($sql);
for ($i=0;$i{
//id值
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['id']='{$result[$i][{$this->idstr}]}';;
//标题
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['title']='{$result[$i][{$this->title}]}';;
//父id
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['pid']='{$result[$i][{$this->pidstr}]}';;
//子id
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['cid']='.implode(',',$this->getchildren($result[$i][$this->idstr])).';;
//目录深度
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['depth']='.$this->getdepth($result[$i][$this->idstr]).';;
//父id的id串
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['pstr']='.$this->getpidstr($result[$i][$this->idstr]).';;
//添加的附加属性
foreach ($this->appendarr as $app)
{
if(empty($app)) continue;
$this->tempcode[] =
\${$this->createarrayname}['{$result[$i][$this->idstr]}']['{$app}']='{$result[$i][{$app}]}';;
}
}
$this->tempcode[] = return \${$this->createarrayname};;
$this->tempcode[] = ?>;
//$content = implode(\n,$this->tempcode);
//print_r($this->tempcode);
$content = implode(\n,$this->tempcode);
//建立文件
$fio=factory::getbaseclass('fileio');
if($this->is_utf8) $content = \xef\xbb\xbf.$content;
$fio->writefile($this->createfilename,$content);
return $content ;
}
}
//加载的文件就是为了,数据库连接
//需要数据库有 select 方法
/*
include_once(dirname(dirname(__file__))./config/config.inc.php);
include_once(classes_path.factryobject.class.php);
$db = factryobject::getdb('indexpush');
$c = new treecache($db);
$c->make();
//exit();
//做分析
include_once(treecache.data.php);
$treecache=isset($treecache) ? $treecache : array();
$rootstr = isset($treecache['root']) ? $treecache['root'] : ;
echo parsetree($treecache,$rootstr);
function parsetree($treecache,$rootstr)
{
$tempstr = ;
$temp = explode(',',$rootstr);
foreach ($temp as $cid)
{
$info = $treecache[$cid];
$cidstr = $info['cid'];
$tempstr .= str_repeat('-',($info['depth']-1)*3);
$tempstr.=$info['title'];
if(empty($info['pid']))
{
//附加操作
}
$tempstr .=
;
if(!empty($info['cid']))
$tempstr .=parsetree($treecache,$info['cid']);
}
return $tempstr;
}
*/
?>
这个类是改善过的,当初做这个的适合,只能是数字的作为数组下标,这次支持字母了
另外就是关于解析
view plaincopy to clipboardprint?
ads_type_file = cache_path.ads_type_arr.data.php;
$this->ads_city_file = cache_path.ads_city_arr.data.php;
}
function make_ads_type()
{
$db = factory::getdb(ads_type);
$tree =factory::getitemclass('treecache');
$tree->set($db);
$tree->tablename=$db->tablename;
$tree->pidstr =ads_type_pid;
$tree->idstr = ads_type_id;
$tree->title = ads_type_name;
$tree->createarrayname =ads_type_arr;
$tree->where = ads_type_state=1 order by ads_type_id desc ;
$tree->appendarr = array(ads_type_info);
$tree->createfilename = $this->ads_type_file;
$tree->is_utf8 = true;
return $tree->make();
}
function get_ads_type_str()
{
$temp_arr = $this->get_ads_type_arr();
$treearr = emptyempty($temp_arr) ? array() : $temp_arr;
$rootstr = isset($temp_arr['root']) ? $temp_arr['root'] : ;
$show_content = $this->__parsetree($treearr,$rootstr,'pares_type_link');
return $show_content;
}
function get_ads_type_arr()
{
return is_file($this->ads_type_file) ? require($this->ads_type_file) : array();
}
function pares_type_link($info)
{
$class_name = ads_type;
$tempstr = [子-添加];
$tempstr .=[编辑];
$tempstr .=[删除];
return $tempstr;
}
//根据提供的类别号取得类别数组
function get_type_arr($type_no=0)
{
$temp_arr = $this->get_ads_type_arr();
$rootstr = $type_no==0 ? (isset($temp_arr['root'])?$temp_arr['root'] : ) : (isset($temp_arr[$type_no]['cid'])?$temp_arr[$type_no]['cid']:);
$temp = explode(',',$rootstr);
$return_temp = array();
foreach($temp as $cid)
{
if(isset($temp_arr[$cid])) $return_temp[$temp_arr[$cid]['id']]=$temp_arr[$cid]['title'];
}
return $return_temp;
}
function make_ads_city()
{
$db = factory::getdb(ads_city);
$tree =factory::getitemclass('treecache');
$tree->set($db);
$tree->tablename=$db->tablename;
$tree->pidstr =ads_city_pid;
$tree->idstr = ads_city_no;
$tree->title = ads_city_name;
$tree->createarrayname =ads_city_arr;
$tree->where = ads_city_state=1 order by ads_city_no desc ;
$tree->appendarr = array(ads_city_info);
$tree->createfilename = $this->ads_city_file;
$tree->is_utf8 = true;
return $tree->make();
}
function get_ads_city_arr()
{
return is_file($this->ads_city_file) ? require($this->ads_city_file) : array();
}
function get_ads_city_str()
{
$temp_arr = $this->get_ads_city_arr();
$treearr = emptyempty($temp_arr) ? array() : $temp_arr;
$rootstr = isset($temp_arr['root']) ? $temp_arr['root'] : ;
$show_content = $this->__parsetree($treearr,$rootstr,'pares_city_link');
return $show_content;
}
function pares_city_link($info)
{
$class_name = ads_city;
$tempstr = [子-添加];
$tempstr .=[编辑];
$tempstr .=[删除];
return $tempstr;
}
//根据提供的城市号取得城市数组
function get_city_arr($city_no=0)
{
$temp_arr = $this->get_ads_city_arr();
$rootstr = $city_no==0 ? (isset($temp_arr['root'])?$temp_arr['root'] : ) : (isset($temp_arr[$city_no])?$temp_arr[$city_no]:);
$temp = explode(',',$rootstr);
$return_temp = array();
foreach($temp as $cid)
{
if(isset($temp_arr[$cid])) $return_temp[$temp_arr[$cid]['id']]=$temp_arr[$cid]['title'];
}
return $return_temp;
}
function __parsetree($treecache,$rootstr,$fuc_str)
{
$tempstr = ;
$temp = explode(',',$rootstr);
if(emptyempty($temp)) return ;
$this->layer=0;
foreach ($temp as $cid)
{
if(isset($treecache[$cid]))
{
$info = $treecache[$cid];
$cidstr = $info['cid'];
//如果下面有子id
if($info[cid]!=)
{
$tempstr .=;
$tempstr .= str_repeat(' ',($info['depth']-1)*3);
if($info[cid]!=)
{
//$tempstr .=;
}
//$tempstr .=>;
$tempstr.=$info['title'];
$tempstr .=$this->{$fuc_str}($info);
$tempstr .=
;
$tempstr .=;
$tempstr .= $this->__parsetree($treecache,$info['cid'],$fuc_str);
$tempstr .=;
}else{
$this->layer++;
$tempstr .= str_repeat(' ',($info['depth']-1)*3);
$tempstr.=$info['title'];
$tempstr .=$this->{$fuc_str}($info);
if($this->isx==true)
{
if($this->layer % $this->rowsize ==0)
$tempstr .=
;
else
$tempstr .= ;
}else{
$tempstr .=
;
}
}
}
}
return $tempstr;
}
}
?>
以上就介绍了无限归来之超级警察 php 无限级缓存的类的扩展,包括了无限归来之超级警察方面的内容,希望对php教程有兴趣的朋友有所帮助。
其它类似信息

推荐信息