数日前に書いた無限分類クラス_PHPチュートリアル

WBOY
リリース: 2016-07-21 15:57:46
オリジナル
754 人が閲覧しました

これは 1 週間前に書きましたが、実際に使ってみると非常にうまく機能しています。

主なアイデアは http://www.phpobject.net/b...[url=http://www.phpobject.net/blog/read.php?49][/url] から来ています

そうではありませんここで原理について詳しく説明してください。コードを送信してください。

PS: このコードは直接使用できないため、他のライブラリ クラスのいくつかと組み合わせる必要があります。ここでは主に分類のアイデアを提供します。

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

/** 
--
-- 表の结构 `daxue8_category`
--

CREATE TABLE `daxue8_category` (
`cid` smallint(6) NOT NULL auto_increment,
`pid` smallint(6) NOT N ULL デフォルト「0」、
`level` smallint(6) NOT NULL default '0',
`cname` char(64) NOT NULL default '',
`lft` smallint(6) NOT NULL default '0',
`rgt` smallint( 6) NOT NULL デフォルト '0',
`uid` mediumint(8) NOT NULL デフォルト '0',
`username` char(32) NOT NULL デフォルト '',
`ctime` int(10) NOT NULL デフォルト ' 0',
`cstate` tinyint(1) NOT NULL デフォルト '0',
`gnum` mediumint(8) NOT NULL デフォルト '0',
`orderstyle` smallint(3) NOT NULL デフォルト '0',
PRIMARY KEY (`cid`)
) TYPE=MyISAM AUTO_INCREMENT=2 ; 

--
-- 表中のデータ `daxue8_category`
--

INSERT INTO `daxue8_category` VALUES (1, 0, 1, 'root', 1, 2, 0, '管理员', 1163608814, 1,0,0); 
*/
クラスカテゴリ
{
var $module;

関数 category()
$this->tbname=TB_PREX ';
$this->module=new module($this->tbname);ノードは存在します
if($node_exist=$this->module->detail('where 「.$pid」とcname=''.$node['cname'].''')){
//$this->error(__FUNCTION__.'(): ノード '.$node['cname'].' はすでに存在します! '); query' '' $pnode['rgt'];
// add t Return $ this- & gt; module- & gt;
}

/**
*ノードを削除
*@param $ cid to ID を削除します
*@param $ delete_childern ノードに子ノードがある場合、強制的に削除するかどうか。設定が true ではなく、子ノードがある場合、削除は失敗し、 false を返します
> ;get_by_cid($cid);
If(($this->child_num($node)>0)&&(! $delete_childern))$this->error(__FUNCTION__.'(): このノードには子ノードがあります。'); // ノードとそのすべてのサブノードを削除します
$ this-> module->
// 対応する左クリック値と右クリック値を変更します
; Plus = $ ノード ['rgt']-$ ノード ['lft']+1; $ This- & gt; クエリ ('update `' ' .$this->tbname.'` set lft=lft-'.$plus.' where lft>'.$node['rgt']);
$this->module->query('update ` '.$this->tbname.'` rgt = rgt-'。$ rgt>'。 ' と '.$node['rgt'];
If(!empty($deep))$where.=' と level<'.$node['level']+$deep;
if( $ Deep == 1) {
$ when. = 'OrdersTyle Desc で注文';
$ when. = 'LFT ASC で注文';
}

/**
*ノードを更新します* /
function get_parent($cid)
{
$node=$this->get_by_cid($cid);
return $this-&g t;module-> ;select('where lft<='.$node[' lft'].' および rgt>='.$node['rgt'].' lft asc'); 
/**
‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐*/
function get_children($pid,$deep=0){
//获取节点情報
$pnode=$this->get_by_cid($pid); 
$where='where lft>'.$pnode['lft'].' そしてrgt if(!empty($deep))$where.=' and level<='.($pnode['level']+$deep); 
if($deep==1){
$where.=' order by orderstyle desc'; 
}else{
$where.='order by lft asc';             
}
return $this->module->select($where); 
}

/**
を使用して*/
function get_level_children($pid,$deep){
//获取节点情報
$pnode=$this->get_by_cid($pid) ; 
$where='where lft>'.$pnode['lft'].' そしてrgt<'.$pnode['rgt']; 
$where.=' and level='.($pnode['level']+$deep); 
$where.=' orderstyle desc で注文'; 
return $this->module->select($where); 
}

/**
使用する 使用するオフ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐*/
function get_by_cid($cid){
$node=$this->module->detail('where cid='.$cid); 
if(!$node)$this->error(__FUNCTION__.'():获取节点'.$cid.'失败!'); T リターン $ ノード
}
/**
*子ノードの数を取得します*/
関数 Child_num ($ ノード) {
リターン ($ ノード [' rgt ']-$ ノード [' lft ']/2 ;
}
/ **&#&*/
関数ディスプレイ($ cid){
$ nodes = $ this-&gt; select($ cid);ノード['レベル']-1).$node['cname']."n"; --------------------------* /

関数 error($msg){
die('ERROR : ファイル '.__FILE__.' 関数 '.$msg);
}
}

;



http://www.bkjia.com/PHPjc/317731.html

www.bkjia.com

tru​​e

http://www.bkjia.com/PHPjc/317731.html

技術記事

これは 1 週間前に書きましたが、実際に使ってみると非常にうまく機能しています。 主なアイデアは次のとおりです: http://www.phpobject.net/b...[url=http://www.phpobject.net/blog/read.php?49][/url] 説明はしませんここでの原則は...

ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!