YII2 无限级分类实用_Yii_青云站长教程网
欢迎来到站长教程网!
  • 秒到短信接口 免费试用
  • 微信支付宝接口 秒结算
  • 中文网站排名|申请加入
  • 搜索引擎全站查询
  • 查询移动网站权重数据
  • 海外主机 台湾公司直销
  • Yii

    当前位置:主页 > 网络编程 > Yii >

    YII2 无限级分类实用

    时间:2019-08-13|栏目:Yii|点击:
  • model 文件 Lib.php 里面

    namespace frontend\models; use Yii; use yii\behaviors\TimestampBehavior; use yii\helpers\ArrayHelper; /** * This is the model class for table "{{%lib}}". * * @property integer $libid * @property string $libname * @property integer $classid * @property integer $isuser * @property integer $isopen * @property string $libimg * @property string $note * @property integer $allowedit * @property integer $allowpractice * @property integer $comments * @property integer $onclick * @property integer $collection_num * @property integer $practice_num * @property integer $xbeans * @property integer $status * @property integer $created_by * @property integer $updated_by * @property integer $created_at * @property integer $updated_at * * @property LibClass $class */ class Lib extends \yii\db\ActiveRecord { public $tree = [] ; /** * @inheritdoc */ public static function tableName() { return '{{%lib}}'; } /** * @inheritdoc */ public function rules() { return [ [['libname', 'classid', 'created_by', 'updated_by'], 'required'], [['classid', 'isuser', 'isopen', 'allowedit', 'allowpractice', 'comments', 'onclick', 'collection_num', 'practice_num', 'xbeans', 'status', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'], [['note'], 'string'], [['libname', 'libimg'], 'string', 'max' => 255], [['libname'], 'unique'], [['classid'], 'exist', 'skipOnError' => true, 'targetClass' => LibClass::className(), 'targetAttribute' => ['classid' => 'classid']], ]; } /** * @inheritdoc */ public function attributeLabels() { $mappath = 'frontend/models/lib'; return [ 'libid' => Yii::t($mappath, 'libid'), 'libname' => Yii::t($mappath, 'libname'), 'classid' => Yii::t($mappath, 'classid'), 'isuser' => Yii::t($mappath, 'isuser'), 'isopen' => Yii::t($mappath, 'isopen'), 'libimg' => Yii::t($mappath, 'libimg'), 'note' => Yii::t($mappath, 'note'), 'allowedit' => Yii::t($mappath, 'allowedit'), 'allowpractice' => Yii::t($mappath, 'allowpractice'), 'comments' => Yii::t($mappath, 'comments'), 'onclick' => Yii::t($mappath, 'onclick'), 'collection_num' => Yii::t($mappath, 'collection_num'), 'practice_num' => Yii::t($mappath, 'practice_num'), 'xbeans' => Yii::t($mappath, 'xbeans'), 'status' => Yii::t($mappath, 'status'), 'created_by' => Yii::t($mappath, 'created_by'), 'updated_by' => Yii::t($mappath, 'updated_by'), 'created_at' => Yii::t($mappath, 'created_at'), 'updated_at' => Yii::t($mappath, 'updated_at'), ]; } /** *when create and update */ public function behaviors() { return [TimestampBehavior::className()]; } /** * @return \yii\db\ActiveQuery */ public function getClass() { return $this->hasOne(LibClass::className(), ['classid' => 'classid']); } /** * @inheritdoc * @return LibQuery the active query used by this AR class. */ public static function find() { return new LibQuery(get_called_class()); } /** * @inheritdoc * */ public function getData() { //$cates = LibClass::find()->asArray()->all(); $cates = LibClass::find()->all(); $cates = ArrayHelper::toArray($cates); return $cates; } public function getCatTree($cats , $bclassid = 0, $nu = 0 ) { $bx = '---|' ; $nu++ ; foreach ($cats as $cat){ $catid = $cat['classid']; $catname = $cat['classname']; $catbid = $cat['bclassid']; $islast = $cat['islast']; if ($catbid == $bclassid) { $this->tree[$catid]= str_repeat($bx, $nu) .'~'. $catname . ($islast ? '_last' : '') . PHP_EOL ; $this->getCatTree($cats, $catid, $nu ) ; } } } public function tree() { $cats = $this->getData(); $this->getCatTree($cats, 0, 0); return $this->tree ; } }

    上一篇:一个很简单的无限级分类

    栏    目:Yii

    下一篇:php 环境自动搭建脚本

    本文标题:YII2 无限级分类实用

    本文地址:http://www.jh-floor.com/wangluobiancheng/Yii/20206.html

    广告投放 | 联系我们 | 版权申明

    重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

    如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

    联系QQ:888888 | 邮箱:888888#qq.com(#换成@)

    Copyright © 2002-2017 青云站长教程网 版权所有 琼ICP备xxxxxxxx号