search
Homephp教程PHP开发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,&#39;zmg_id&#39;,MemGroup::model()->getMemGroup(),array(
    &#39;class&#39;=>&#39;s_ipt w_120&#39;,
    &#39;empty&#39;=>&#39;请选择会员组&#39;,
    &#39;ajax&#39; =>array(
          &#39;type&#39;=>&#39;GET&#39;,
          &#39;url&#39;=>CController::createUrl(&#39;cmpTemplates/getMemType&#39;),
          &#39;update&#39;=>&#39;#CmpTemplates_zmg_ids&#39;,
          &#39;data&#39;=>array(&#39;mid&#39;=>"js:this.value")
          ),
    ))?>
<?php echo $form->dropDownList($model,&#39;zmg_ids&#39;,array(),array(&#39;class&#39;=>&#39;s_ipt w_120&#39;,&#39;empty&#39;=>&#39;选择会员等级&#39;))?>

2. Controller

/**
 * 获取会员组,对应的会员等级,用于下拉菜单
 */
public function actionGetMemType($mid=0)
{
  $criteria=new CDbCriteria;
  $criteria->compare(&#39;zmg_id&#39;,$mid);
  $memType = MemType::model()->findAll($criteria);
  $name = &#39;选择会员等级&#39;;
  echo CHtml::tag(&#39;option&#39;, array(&#39;value&#39;=>0), $name, true);
  foreach($memType as $val) {
    echo CHtml::tag(&#39;option&#39;, array(&#39;value&#39;=>$val->zmt_id),CHtml::encode($val->zmt_title),true);
  }
}

3. Model

/*
* 取会员组信息
*/
public function getMemGroup($type=null){
  if($type==null){
    $criteria=new CDbCriteria;
    $criteria->compare(&#39;type&#39;,&#39;1&#39;);
    $memGroup = MemGroup::model()->findAll($criteria);
    return CHtml::listData($memGroup,&#39;zmg_id&#39;,&#39;zmg_title&#39;);
  }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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.