ホームページ php教程 php手册 PHP 無制限キャッシュ クラス拡張

PHP 無制限キャッシュ クラス拡張

Jun 13, 2016 pm 12:24 PM
php コード 使用 減らす 分類 関数 コピー 確立する 拡大する 無制限 状態 親切 カテゴリー キャッシュ

コードをコピー コードは次のとおりです:


<?php
/**
* 機能: 条件に基づいてカテゴリ キャッシュを作成し、カテゴリの使用量を削減します
* 作成日: Thu May 31 15:55:11 CST 2007
* 最終更新日:
* 著者: sanshi <sanshi0815 @トム.com>
*/

classtreeCache
{
var $tableName = "index_category" //テーブル名<🎜; >var $where = "1"; //条件
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() ; //追加の属性、フィールド名はデータ内の名前に対応する必要があります。 set($db)
{
$this->db = $db;
$this->tempCode[] = "
}
;すべてのレベル 1 を取得します
function 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 = "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;
関数 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(empty($this->createFileName))
$this->createFileName = "{$this->createArrayName}.data.php";

$rootArr = $this->getRootID(); {$this->idStr},{$this->title},{$this->pidStr}";
foreach ($this->appendArr as $app)
{
if(emptyempty($app )) 続行;
$selectF .=",{$app}";
}
$sql = "{$this->tableName} から {$selectF} を選択します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}"]}' ;";
//Subid
$this->tempCode[] =
"${$this->createArrayName}['{$result[$i][ $this->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->gt;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); ;
}
}
//ロードされるファイルはデータベース接続用です
//データベースには選択メソッドが必要です
/*
include_once(dirname(dirname( __FILE__)). "/config/config.inc.php");
include_pATH."factryObject.class.php"); ;
$c = new TreeCache($db);
$c->make()
//exit(); "treeCache.data .php");
$treeCache=isset($treeCache) ? $treeCache : array();
$rootStr = isset($treeCache['root']) ? '] : " ";
echo parseTree($treeCache,$rootStr);
{
$tempStr = ""; explode(', ',$rootStr);
foreach ($temp AS $cid)
{
$info = $treeCache[$cid];
$cidStr = $info['cid' ];
$tempStr .= str_repeat('-',($info['深さ']-1)*3);
$tempStr.=$info['title']; empty($info ['pid']))
{
//追加の操作
}
$tempStr .= "<br/>"
if(!empty( $info[' cid']))
$tempStr .=parseTree($treeCache,$info['cid']);
}
return $tempStr;
?
<?php
/**
* 機能: 条件に基づいてカテゴリ キャッシュを作成し、カテゴリの使用量を削減します
* 作成日: Thu May 31 15:55:11 CST 2007
* 最終更新日:
* 著者: sanshi <sanshi0815 @トム.com>
*/

クラス ツリーキャッシュ
{
var $tableName = "index_category"; name
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 ="" //作成されたファイルの名前
; $appendArr = array(); //追加の属性。フィールド名はデータ内の名前に対応する必要があります。
var $is_utf8 = false
function TreeCache()
{
} <🎜; >関数セット($db)
{
$this->db = $db;
$this->tempCode[] = "<?php";
//レベル 1 をすべて取得します
function 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 = "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);
}
//深度を取得します
関数 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) ) 続行;
$selectF .=",{$app}";
}
$sql = "{$this-> から SELECT {$selectF} ;tableName} WHERE
{$this ->where}";
$result = $this->db->select($sql);
for ($i=0;$i&lt) ;count($result);$i )
{
//id 値
$this->tempCode[] =
"${$this->createArrayName}['{$結果[$i][$this-&gt ;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[] = "${$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 =factoryObject::getDB('indexPush');
$c = 新しいツリーキャッシュ($db);
$c->make();
//終了();

//做分析
include_once("treeCache.data.php");
$treeCache=isset($treeCache) ? $treeCache : array();
$rootStr = isset($treeCache['root']) ? $treeCache['root'] : "";
echo parseTree($treeCache,$rootStr);
関数 parseTree($treeCache,$rootStr)
{
$tempStr = "";
$temp =explode(',',$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;
}
*/
?>

この種は改善されています、当初はこれを行っています、唯一能は数字の数として機能します、次は文字母了

另外就は解析に関するものです

プレーンコピーをクリップボードプリントに表示しますか?
<?php
class parseTree
{
var $ads_type_file = "";
var $isX = false;
var $rowSize=2;
function 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->テーブル名=$db->テーブル名;
$tree->pidStr ="ads_type_pid";
$tree->idStr = "ads_type_id";
$tree->title = "広告タイプ名";
$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();
}
関数 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');
$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 = "[<a href="?c={$class_name}&m=add&ads_type_pid={$info[" href="?c={$class_name}&m=add&ads_type_pid={$info["id ']}'>子-追加</a>]";
$tempStr .="[<a href="?c={$class_name}&m=edit&ads_type_id={$info[" href="?c={$class_name}&m=edit&ads_type_id={$info[" id']}'>编辑</a>]";
$tempStr .="[<a href="?c={$class_name}&m=del&ads_type_id={$info[" href="?c={$class_name}]&m=del&ads_type_id={$info["id']}'>删除</a>]";
$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]['タイトル'];
}
return $return_temp;
}

function make_ads_city()
{
$db = Factory::getDB("ads_city");
$tree =Factory::getItemClass('treeCache');
$tree->set($db);
$tree->テーブル名=$db->テーブル名;
$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 = emptyempty($temp_arr) ? array() : $temp_arr;
$rootStr = isset($temp_arr['root']) ? $temp_arr['root'] : "";
$show_content = $this->__parseTree($treeArr,$rootStr,'pares_city_link');
$show_content を返す;
}
function 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 ']}'>子-追加</a>]";
$tempStr .="[<a href="?c={$class_name}&m=edit&ads_city_no={$info[" href="?c={$class_name}&m=edit&ads_city_no={$info[" id']}'>编辑</a>]";
$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 を返す;
}
//提供による城市号取得城市数组
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]['タイトル'];
}
return $return_temp;
}

関数 __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 .="<div >";
$tempStr .= str_repeat(' ',($info['深さ']-1)*3);
if($info["cid"]!="")
{
//$tempStr .="<img src="/images/arrow.jpg" src="images/arrow .jpg" style="カーソル:手;" style="カーソル:手;" onClick='javascript:ShowMenu("l_{$info['id']}");' id='pic_l_{$info['id']}'>";
}
//$tempStr .=">";
$tempStr.=$info['title'];
$tempStr .=$this->{$fuc_str}($info);
$tempStr .="</div>";
$tempStr .="<div id='l_{$info['id']}' >";
$tempStr .= $this->__parseTree($treeCache,$info['cid'],$fuc_str);
$tempStr .="</div>";
}else{
$this-> レイヤー ;
$tempStr .= str_repeat(' ',($info['深さ']-1)*3);
$tempStr.=$info['title'];
$tempStr .=$this->{$fuc_str}($info);
if($this->isX==true)
{
if($this->layer % $this->rowSize ==0)
$tempStr .= "&lt ;br/>";
else
$tempStr .= " ";
}else{
$tempStr .= "<br/>";
}
}
}
}
return $tempStr;
}
}
?>

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットな記事タグ

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

CakePHP の日付と時刻 CakePHP の日付と時刻 Sep 10, 2024 pm 05:27 PM

CakePHP の日付と時刻

Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Dec 24, 2024 pm 04:42 PM

Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド

CakePHP ファイルのアップロード CakePHP ファイルのアップロード Sep 10, 2024 pm 05:27 PM

CakePHP ファイルのアップロード

CakePHP ルーティング CakePHP ルーティング Sep 10, 2024 pm 05:25 PM

CakePHP ルーティング

CakePHP について話し合う CakePHP について話し合う Sep 10, 2024 pm 05:28 PM

CakePHP について話し合う

CakePHP プロジェクトの構成 CakePHP プロジェクトの構成 Sep 10, 2024 pm 05:25 PM

CakePHP プロジェクトの構成

CakePHP クイックガイド CakePHP クイックガイド Sep 10, 2024 pm 05:27 PM

CakePHP クイックガイド

CakePHP バリデータの作成 CakePHP バリデータの作成 Sep 10, 2024 pm 05:26 PM

CakePHP バリデータの作成

See all articles