백엔드 개발 PHP 튜토리얼 Infinite Return: Super Police PHP 무한 캐시 클래스 확장

Infinite Return: Super Police PHP 무한 캐시 클래스 확장

Jul 29, 2016 am 08:39 AM

코드 복사 코드는 다음과 같습니다.


<?php
/**
* 기능: 조건에 따라 카테고리 캐시를 생성하여 카테고리 사용량을 줄입니다.
* 생성일: 2007년 5월 31일 목요일 15:55:11 CST
* 최종 업데이트:
* 작성자: sanshi <sanshi0815 @tom.com>*/
class treeCache
{
var $tableName = "index_category" //테이블 이름
var $ where = "1"; //where 조건
var $pidStr ="i_c_pid"; //pid의 필드 이름
var $tempCode = array() //생성된 파일의 배열
var $pid = '0'; //pid
var $db; //데이터베이스 핸들
var $idStr="i_c_id"; //얻은 데이터 ID
var $title = "i_c_cn"; //이름 필드
var $createArrayName = "treeCache"; //생성된 배열의 이름
var $createFileName ="" //생성된 파일의 이름
var $appendArr = array( ); // 추가 속성에서는 필드 이름이 데이터의 이름과 일치해야 합니다.
var $is_utf8 = false
function treeCache()
{
}
function set($db )
{
$this->db = $db;
$this->tempCode[] = "<?php"
}
//모두 먼저 가져오기- level
functions getRootID()
{
$sql = "SELECT {$this->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 = "{$this->tableName} WHERE
{$this->pidStr}='{$pid}' AND {$this->where}에서 {$this ->idStr} 선택 ";
$result = $this->db->select($sql);
$temp = array()
foreach($result as $r)
{
$ temp[]=$r ["{$this->idStr}"];
}
return $temp>}
//남편 ID 가져오기
function getParent($cid; )
{
$sql = "{$this->tableName}에서 {$this->pidStr}을 선택하세요.
{$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)
',',$temp );
}
//깊이 가져오기
function getDepth($cid,$length=0)
{
$pid=$this->getParent ($cid);
$깊이 ;
if( $pid != $this->pid && !emptyempty($pid))
$length = $this->getDepth($pid, $깊이);
반환 $깊이;}
//파일 만들기
function make()
{
if(emptyempty($this->createFileName))
$this->createFileName = "{$this->createArrayName}.data.php"
$rootArr = $this->getRootID()
$selectF = "{$this-&gt ;idStr},{$this ->title},{$this->pidStr}";
foreach ($this->appendArr as $app)
{
if(emptyempty($ 앱)) 계속
$selectF .=",{$app}";
}
$sql = "{$this->tableName} WHERE
에서 {$selectF} 선택 $this->where} ";
$result = $this->db->select($sql);
for ($i=0;$i<count($result);$ 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-&gt ;createArrayName}['{$ 결과[$i][$this->idStr]}']['pid']='{$result[$i]["{$this->pidStr}"]} ';";
//하위 ID
$this->tempCode[] =
"${$this->createArrayName}['{$result[$i][$this-&gt ;idStr]}'][ 'cid']='".implode(',',$this->getChildren($result[$i]["$this->idStr"]))."'; ";
// 디렉터리 깊이
$this->tempCode[] =
"${$this->createArrayName}['{$result[$i][$this->idStr ]}']['깊이 ']='".$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}['{$ 결과[$i][$this->idStr]}']['{$app}']='{$result[$i]["{$app}"]} ';";
}
}
$this->tempCode[] = "${$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 = "xEFxBBxBF".$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'] : "";
echoparTree($treeCache,$rootStr);
function parTree($treeCache,$rootStr)
{
$tempStr = ""; $rootStr);
foreach ($temp AS $cid)
{
$info = $treeCache[$cid]
$cidStr = $info['cid']; tempStr .= str_repeat ('-',($info['깊이']-1)*3)
$tempStr.=$info['title']
if(empty($info[' pid']) )
{
//추가 작업
}
$tempStr .= "<br/>"
if(!empty($info['cid'; ]))
$tempStr .=parseTree($treeCache,$info['cid'])
}
return $tempStr;
}
*/
?>
&lt ;?php
/**
* 기능: 조건에 따라 카테고리 캐시를 생성하여 카테고리 사용량을 줄입니다.
* 생성일: 2007년 5월 31일 목요일 15:55:11 CST
* 최종 업데이트:
* 작성자: sanshi <sanshi0815 @tom.com>*/
class treeCache
{
var $tableName = "index_category"; //테이블 이름
var $where = " 1"; / /where 조건
var $pidStr ="i_c_pid"; //pid의 필드 이름
var $tempCode = array(); //생성된 파일의 배열
var $pid = '0 '; // pid
var $db; //데이터베이스 핸들
var $idStr="i_c_id"; //얻은 데이터 ID
var $title = "i_c_cn";
var $createArrayName = "treeCache"; //생성된 배열의 이름
var $createFileName =""; //생성된 파일의 이름
var $appendArr = array(); 추가 속성에는 필드 이름이 필요합니다. 데이터의 이름에 해당합니다.
var $is_utf8 = false
function treeCache()
{
}
function set($db)
{
$this-&gt ;db = $db;
$this->tempCode[] = "<?php"
}
//모든 레벨 1 가져오기
function getRootID( )
{
$sql = "{$this->tableName} WHERE
{$this->pidStr}='{$this->에서 {$this->idStr}을 선택하세요. pid}' AND { $this->where} ";
//exit($sql);
$result = $this->db->select($sql);
$ temp = array() ;
foreach ($result as $r)
{
$temp[]=$r["{$this->idStr}"]
}
$this-&gt ;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($r로 $result)
{
$temp[]=$r[ "{$this-&gt ;idStr}"];
}
return $temp;}
//남편 ID 가져오기
function getParent($cid)
{
$sql = "{$this->tableName} WHERE
{$this->idStr}='{$cid}' AND {$this->where에서 {$this->pidStr} 선택 } ";
$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,$length=0)
{
$pid=$this->getParent($cid)
$깊이
if( $pid != $this->pid && !empty($pid))
$깊이 = $this->getDepth($pid,$깊이)
return $length
}
//파일 만들기
function make()
{
if(empty($this->createFileName))
$this->createFileName = "{$this-&gt ;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 = "{$this->tableName} WHERE
{$this->where}에서 {$selectF} 선택 ";
$result = $this->db->select($sql);
for ($i=0;$i<count($result);$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"]))."';";
/ /目录深degree
$this->tempCode[] =
"${$this->createArrayName}['{$result[$i][$this->idStr]}'][' 깊이']='".$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[] = "${$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 = "xEFxBBxBF".$content;
$fio->writeFile($this->createFileName,$content);
$content 반환 ; " /config/config.inc.php");
include_once(CLASSES_PATH."factryObject.class.php");
$db =factryObject::getDB('indexPush');
$c = 새로운 treeCache($db);
$c->make();
//exit();
//做分析
include_once("treeCache.data.php");
$treeCache=isset($treeCache) ? $treeCache : 배열();
$rootStr = isset($treeCache['root']) ? $treeCache['루트'] : "";
echo parTree($treeCache,$rootStr);
함수 parseTree($treeCache,$rootStr)
{
$tempStr = "";
$temp = 폭발(',',$rootStr);
foreach ($temp AS $cid)
{
$info = $treeCache[$cid];
$cidStr = $info['cid'];
$tempStr .= str_repeat('-',($info['깊이']-1)*3);
$tempStr.=$info['제목'];
if(empty($info['pid']))
{
//附加操작
}
$tempStr .= "<br/>";
if(!empty($info['cid']))
$tempStr .=parseTree($treeCache,$info['cid']);
}
$tempStr을 반환합니다.
}
*/
?>
这个类是改善过的, 当初做这个的适了析
일반 사본을 클립보드 인쇄로 보시겠습니까?
<?php
class parTree
{
var $ads_type_file = "";
var $isX = false;
var $rowSize=2;
함수 parseTree()
{
$this->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 = "광고_유형_이름";
$tree->createArrayName ="ads_type_arr";
$tree->where = "ads_type_state=1 ORDER BYads_type_id DESC";
$tree->appendArr = array("ads_type_info");
$tree->createFileName = $this->ads_type_file;
$tree->is_utf8 = true;
return $tree->make();
}
함수 get_ads_type_str()
{
$temp_arr = $this->get_ads_type_arr();
$treeArr = 비어있음($temp_arr) ? 배열() : $temp_arr;
$rootStr = isset($temp_arr['root']) ? $temp_arr['root'] : "";
$show_content = $this->__parseTree($treeArr,$rootStr,'pares_type_link');
$show_content 반환;
}
function get_ads_type_arr()
{
return is_file($this->ads_type_file) ? require($this->ads_type_file) : array();
}
함수 pares_type_link($info)
{
$class_name = "ads_type";
$tempStr = "[<a href="?c={$class_name}&m=add&ads_type_pid={$info[" href="?c={$class_name}&m=add&ads_type_pid={$info["id ']}'>자-添加]";
$tempStr .="[<a href="?c={$class_name}&m=edit&ads_type_id={$info[" href="?c={$class_name}&m=edit&ads_type_id={$info[" id']}'>编辑]";
$tempStr .="[<a href="?c={$class_name}&m=del&ads_type_id={$info[" href="?c={$class_name}&m=del&ads_type_id={$info[" ID']}'>删除</a>]";
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 =explore(',',$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();
}
함수 get_ads_city_str()
{
$temp_arr = $this->get_ads_city_arr();
$treeArr = 비어있음($temp_arr) ? 배열() : $temp_arr;
$rootStr = isset($temp_arr['root']) ? $temp_arr['root'] : "";
$show_content = $this->__parseTree($treeArr,$rootStr,'pares_city_link');
$show_content 반환;
}
함수 pares_city_link($info)
{
$class_name = "ads_city";
$tempStr = "[<a href="?c={$class_name}&m=add&ads_city_pid={$info[" href="?c={$class_name}&m=add&ads_city_pid={$info["id ']}'>자-添加]";
$tempStr .="[<a href="?c={$class_name}&m=edit&ads_city_no={$info[" href="?c={$class_name}&m=edit&ads_city_no={$info[" id']}'>编辑]";
$tempStr .="[<a href="?c={$class_name}&m=del&ads_city_no={$info[" href="?c={$class_name}&m=del&ads_city_no={$info[" id']}'>删除</a>]";
$tempStr 반환;
}
//根据提供적거리도시号取得citycity数组
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 = 폭발(',',$rootStr);
$return_temp = 배열();
foreach($temp를 $cid로)
{
if(isset($temp_arr[$cid])) $return_temp[$temp_arr[$cid]['id']]=$temp_arr[$ cid]['제목'];
}
$return_temp를 반환합니다.
}
함수 __parseTree($treeCache,$rootStr,$fuc_str)
{
$tempStr = "";
$temp = 폭발(',',$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 .="<div >";
$tempStr .= str_repeat(' ',($info['깊이']-1)*3);
if($info["cid"]!="")
{
//$tempStr .="<img src="/images/arrow.jpg" src="이미지/화살표 .jpg" ID']}'>";
}
//$tempStr .=">";
$tempStr.=$info['제목'];
$tempStr .=$this->{$fuc_str}($info);
$tempStr .="</div>";
$tempStr .="<divid']}' >";
$tempStr .= $this->__parseTree($treeCache,$info['cid'],$fuc_str);
$tempStr .="</div>";
}else{
$this->레이어 ;
$tempStr .= str_repeat(' ',($info['깊이']-1)*3);
$tempStr.=$info['제목'];
$tempStr .=$this->{$fuc_str}($info);
if($this->isX==true)
{
if($this->layer % $this->rowSize ==0)
$tempStr .= "&lt ;br/>";
그 외
$tempStr .= " ";
}else{
$tempStr .= "<br/>";
}
}
}
}
return $tempStr;
}
}
?>

以上就介绍了无限归来之超级警察 php 无限级缓存的类的扩 Exhibition, 包括了无限归来 超级警察方면적内容,希望对PHP에는 다양한 기능이 있습니다.

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

뜨거운 기사 태그

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

11 최고의 PHP URL 쇼트너 스크립트 (무료 및 프리미엄) 11 최고의 PHP URL 쇼트너 스크립트 (무료 및 프리미엄) Mar 03, 2025 am 10:49 AM

11 최고의 PHP URL 쇼트너 스크립트 (무료 및 프리미엄)

Laravel의 플래시 세션 데이터로 작업합니다 Laravel의 플래시 세션 데이터로 작업합니다 Mar 12, 2025 pm 05:08 PM

Laravel의 플래시 세션 데이터로 작업합니다

Laravel 테스트에서 단순화 된 HTTP 응답 조롱 Laravel 테스트에서 단순화 된 HTTP 응답 조롱 Mar 12, 2025 pm 05:09 PM

Laravel 테스트에서 단순화 된 HTTP 응답 조롱

Instagram API 소개 Instagram API 소개 Mar 02, 2025 am 09:32 AM

Instagram API 소개

Laravel Back End : Part 2, React가있는 React 앱 구축 Laravel Back End : Part 2, React가있는 React 앱 구축 Mar 04, 2025 am 09:33 AM

Laravel Back End : Part 2, React가있는 React 앱 구축

PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법 PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법 Mar 14, 2025 am 11:42 AM

PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법

Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트 Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트 Mar 13, 2025 pm 12:08 PM

Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트

2025 PHP 상황 조사 발표 2025 PHP 상황 조사 발표 Mar 03, 2025 pm 04:20 PM

2025 PHP 상황 조사 발표

See all articles