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

      

  • 相关阅读:
    .NET Core 调用百度 PaddleOCR 识别图文
    ASP.NET Core 查看应用状态和统计
    锐浪报表 winform程序 数据源设置为excel时提示用户名密码隐藏
    单例
    WPF 设计器一直加载一分钟才显示
    .net 5 SignalR WPF 服务端+客户端
    WPF 使用Image 捕获摄像头数据,并将image改为圆形
    Vue Element-ui Table实现动态新增和删除
    Element-UI 中使用rules验证
    @Value读取不到配置文件的值
  • 原文地址:https://www.cnblogs.com/haiwei_sun/p/3607782.html
Copyright © 2011-2022 走看看