本文实例讲述了yii实现的多级联动下拉菜单。分享给大家供大家参考,具体如下:
1. 视图文件
<?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. 控制器
/**
* 获取会员组,对应的会员等级,用于下拉菜单
*/
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. 模型
/*
* 取会员组信息
*/
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];
}
}
}
更多关于yii相关内容感兴趣的读者可查看本站专题:《yii框架入门及常用技巧总结》、《php优秀开发框架总结》、《smarty模板入门基础教程》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于yii框架的php程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!