YII 无限分类

YII的无限分类,首先整个无限分类的类,使用这个类http://www.thinkphp.cn/code/170.html放到protected/components/Tool.php

然后控制器中

public function actionadd(){
        $model = new Archive();
        if($_POST['Archive']){
            $model->attributes = $_POST['Archive'];            
            if($model->save()){
                Yii::app()->user->setFlash('success','添加文档成功');
                $this->redirect(array('index'));
            }
        }
        $list=Yii::app()->db->createCommand("select id,typename,topid from {{arctype}} order by topid asc,id desc")->query()->readAll();
        $type = Tool::tree($list);        
        $this->renderPartial('add',array('model'=>$model,'type'=>$type));
    }



视图中

<tr>
          <td width="159">&nbsp;<?php echo $form->labelEx($model,'typeid');?>:</td>
          <td width='901'>
            <select name="Archive[typeid]" id="typeid">
            <option value="" selected="selected">请选择栏目</option>
              <?php foreach($type as $k=>$v){?>
              <option value="<?php echo $v['id'];?>">
              <?php 
			echo '| '.str_repeat('----',$v['Count']);
			if($v['id']!==1){echo '| -- ';} 
			echo $v['typename'];
			?></option>
            <?php }?>
            </select><?php echo $form->error($model,'typeid');?></td>
        </tr>



你可能感兴趣的:(YII 无限分类)