Ejemplo n.º 1
0
 static function category()
 {
     $db = Yii::app()->db->createCommand();
     $db->setFetchMode(PDO::FETCH_OBJ);
     $rows = $db->from('category')->queryAll();
     if ($rows) {
         foreach ($rows as $v) {
             $tree[$v->id] = $v;
         }
         $category = ArrHelper::tree($tree);
     }
     return array($category, $tree);
 }
Ejemplo n.º 2
0
 /**
 	* 向下生成tree,返回的是数组 
 	* 给select框使用
 $all = \application\modules\auth\models\Group::find()->all();
 	foreach($all as $v){
 		$out[$v->id] = $v->attributes;
 	} 
 	$d = \application\core\Arr::tree($out);
 	echo 'out:<br>';
 	dump($d);
 $all = Classes::all('taxonomy',array('orderBy'=>'sort desc,id desc'),true);   
  	foreach($all as $v){
 		$taxonomy[$v->id] = $v;
 	} 
 	$all = \application\core\Arr::tree($taxonomy); 
 */
 static function tree($data = array(), $value = 'name', $id = 'id', $pid = 'pid', $root = 0)
 {
     self::$tree = array();
     $ids = self::_tree_id($data, $value, $id, $pid, $root);
     $out = self::loop($data, $ids, $value);
     return $out;
 }
Ejemplo n.º 3
0
<?php

/**
* language 表配置
*/
$db = Yii::app()->db->createCommand();
$db->setFetchMode(PDO::FETCH_OBJ);
$rows = $db->from('category')->queryAll();
if ($rows) {
    foreach ($rows as $v) {
        $tree[$v->id] = $v;
    }
    $arr = ArrHelper::tree($tree);
}
$arr[0] = __('please select');
/**
* 分类 默认第一个显示PID为0的,
* 一层层向下,直到没有下层,将不显示超链接,直接显示字段name的值
*/
function admin_config_category($v)
{
    $row = Yii::app()->db->createCommand()->from('category')->where("pid=:pid", array(':pid' => $v['id']))->queryRow();
    if ($row) {
        return "<a href='" . url('admin/category/index', array('pid' => $v['id'])) . "'>" . $v['name'] . "</a>";
    }
    return $v['name'];
}
return array('name' => array('type' => 'input', 'index' => true, '_value' => "php:admin_config_category"), 'pid' => array('type' => 'select', 'datas' => $arr), '_rules' => array(array('name', 'required')), '_error' => 1);