Multi-level linkage drop-down menu implemented in Yii
The example of this article describes the multi-level linkage drop-down menu implemented by Yii. Share it with everyone for your reference, the details are as follows:
1. View file
<?php echo CHtml::activeDropDownList($model,'zmg_id',MemGroup::model()->getMemGroup(),array( 'class'=>'s_ipt w_120', 'empty'=>'请选择会员组', 'ajax' =>array( 'type'=>'GET', 'url'=>CController::createUrl('cmpTemplates/getMemType'), 'update'=>'#CmpTemplates_zmg_ids', 'data'=>array('mid'=>"js:this.value") ), ))?> <?php echo $form->dropDownList($model,'zmg_ids',array(),array('class'=>'s_ipt w_120','empty'=>'选择会员等级'))?>
2. Controller
/** * 获取会员组,对应的会员等级,用于下拉菜单 */ public function actionGetMemType($mid=0) { $criteria=new CDbCriteria; $criteria->compare('zmg_id',$mid); $memType = MemType::model()->findAll($criteria); $name = '选择会员等级'; echo CHtml::tag('option', array('value'=>0), $name, true); foreach($memType as $val) { echo CHtml::tag('option', array('value'=>$val->zmt_id),CHtml::encode($val->zmt_title),true); } }
3. Model
/* * 取会员组信息 */ public function getMemGroup($type=null){ if($type==null){ $criteria=new CDbCriteria; $criteria->compare('type','1'); $memGroup = MemGroup::model()->findAll($criteria); return CHtml::listData($memGroup,'zmg_id','zmg_title'); }else{ $level = $this->getMemGroup(); if(array_key_exists($type,$level)){ return $level[$type]; } } }
I hope this article will be helpful to everyone’s PHP programming based on the Yii framework .
For more articles related to the multi-level linkage drop-down menu implemented by Yii, please pay attention to the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
