Multi-level linkage drop-down menu implemented by Yii and yii linkage drop-down menu
This example describes the multilevel linkage drop-down menu implemented by Yii. We will share this with you for your reference. The details are as follows:
1. View File
<? Php echo CHtml: activeDropDownList ($ model, 'zmg _ id', MemGroup: model ()-> getMemGroup (), array ('class' =>'s _ ipw_120 ', 'empty' => 'select member group ', '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 _ id', array (), array ('class' =>'s _ ipw_120 ', 'empty' => 'select membership level')?>
2. Controller
/*** Obtain the membership level of the member group, which is used in the drop-down menu */public function actionGetMemType ($ mid = 0) {$ criteria = new CDbCriteria; $ criteria-> compare ('zmg _ id', $ mid); $ memType = MemType: model ()-> findAll ($ criteria ); $ name = 'select member level'; 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
/** Get member group information */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] ;}}