在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.在catalog类里面: /** * 级联显示 * 分类目录递归列表 * 返回父类的所有子类 * &$categoryList 引用传值返回 */ 2.控制器映射: $this->render('create',array( 'model'=>$model, 'categorys'=>Category::model()->showAllSelectCategory(Yii::app()->params['module']['article']), )); 3.视图: <div class="row"> <?php echo $form->labelEx($model,'cid'); ?> <?php echo $form->dropDownList($model,'cid',$categorys); ?> </div>
扩展INDEX页面的下拉搜索功能: 控制器代码: if(!empty($_GET['cid'])){ $categoryList=array(); $categoryList[]=$_GET['cid']; Category::model()->getAllCategoryIds($categoryList,Category::model()->findAll('module='.Yii::app()->params['module']['article']),$_GET['cid']); $criteria->addInCondition('cid',$categoryList); } if(!empty($_GET['title'])) $criteria->addSearchCondition('title',$_GET['title']); $dataProvider=new CActiveDataProvider('Article',array( 'criteria'=>$criteria, 'pagination'=>array( 'pageSize'=>Yii::app()->params['girdpagesize'], ), )); 类里面递归把符合条件的之类也查找出来: public function getAllCategoryIds(&$categoryList,$category,$parentid=0){ foreach($category as $k=>$v){ if($v['parentid']==$parentid){ $categoryList[]=$v['id']; $this->getAllCategoryIds($categoryList,$category,$v['id']); } } }
|
2022-08-17
2022-11-06
2022-07-18
2022-08-17
2022-07-18
请发表评论