zoukankan      html  css  js  c++  java
  • yii无限极分类

    	/**
    	 * 获取菜单Tree
    	 *
    	 * @return multitype:
    	 */
    	public function getMenuAllList() {
    		$resArr = $this->getTreeChilds ( 0 );
    		$arr = array ();
    		$arr [0] = "作为一级菜单";
    		foreach ( $resArr as $rs ) {
    			$id = $rs ['id'];
    			$text = $rs ['text'];
    			$arr [$id] = $text;
    		}
    		return $arr;
    	    //return $resArr = CHtml::listData ( $arr, 'id', 'text');
    	}
    	public function getTreeChilds($parentid) {
    		$icon = array (
    				'├─ ',
    				'├─ ',
    				'└─ ' 
    		);
    		$rs = Menu::model ()->findAll ( "parentid=:parentid", array (
    				'parentid' => $parentid 
    		) );
    		$returnArr = array ();
    		if (count ( $rs ) > 0) {
    			
    			for($i = 0; $i < count ( $rs ); $i ++) {
    				if ($parentid > 0) {
    					
    
    					$strnbsp = str_repeat ( '    ', $rs [$i] ['level'] );
    					
    					if (count($rs)==1) {
    						$strnbsp .= $icon [2];
    					}else{
    						if ($i == 0) {
    							$strnbsp .= $icon [0];
    						} elseif ($i == count ( $rs ) - 1) {
    							$strnbsp .= $icon [2];
    						} else {
    							$strnbsp .= $icon [1];
    						}
    					}
    					
    					$returnArr [Menu::$ii] ['id'] = $rs [$i] ['id'];
    					$returnArr [Menu::$ii] ['text'] = $strnbsp. $rs [$i] ['text'];
    				} else {
    					$returnArr [Menu::$ii] ['id'] = $rs [$i] ['id'];
    					$returnArr [Menu::$ii] ['text'] = $rs [$i] ['text'];
    				}
    				$childArr = $this->getTreeChilds ( $rs [$i] ['id'] );
    				if (count ( $childArr ) > 0) {
    					foreach ( $childArr as $child ) {
    						array_push ( $returnArr, $child );
    					}
    				}
    				Menu::$ii ++;
    			}
    		}
    		return $returnArr;
    	}
    	public function beforeSave() {
    		if (parent::beforeSave ()) {
    			if ($this->isNewRecord) {
    				$this->create_time = time ();
    			}
    			// 更改菜单层次
    			if ($this->parentid == 0) {
    				$this->level = 0;
    			} else {
    				$this->level = $this->parentid;
    			}
    			
    			return true;
    		} else {
    			return false;
    		}
    	}
    

      

    <div class="row">
    		<?php echo $form->labelEx($model,'parentid'); ?>
    		<?php echo $form->dropDownList($model,'parentid',Menu::model()->getMenuAllList(),array('encode'=>false)); ?>
    		<?php echo $form->error($model,'parentid'); ?>
    	</div>
    

    db:

     * @property integer $id

     * @property integer $parentid

     * @property string $text

     * @property string $alias_name

     * @property string $icon_cls

     * @property integer $issort

     * @property string $href

     * @property string $level

     * @property integer $create_time

      

  • 相关阅读:
    RestTemplateConfig写法,用于配置Template引擎模板
    RedisUtil写法,好用
    ftpUtil写法,记录一下
    生成唯一id写法,雪花算法
    base64编码转图片,图片转base64编码
    MultipartFile上传图片的写法,记录一下。
    httpClientUtil的put请求
    httpClientUtil的post请求
    python time和datetime
    ubuntu16.04TLS软件源update
  • 原文地址:https://www.cnblogs.com/haiwei_sun/p/3607782.html
Copyright © 2011-2022 走看看