Table of Contents
How to implement cascading drop-down menu in yii, implement drop-down menu in yii
How to use drop-down menu to filter in yii framework
How to make a drop-down menu in yii, it is not linked to the second level, it is the kind that if I want to send an email to someone, I can have a drop-down menu to choose who I want to send it to
Home Backend Development PHP Tutorial How to implement cascading drop-down menu in yii, implement drop-down menu in yii_PHP tutorial

How to implement cascading drop-down menu in yii, implement drop-down menu in yii_PHP tutorial

Jul 13, 2016 am 10:21 AM
yii

How to implement cascading drop-down menu in yii, implement drop-down menu in yii

This article details the method of implementing cascading drop-down menus in Yii. The specific steps are as follows:

1. Add the following code to the template:

<?php
 echo $form->dropDownList($model, 'src_type_id', OrderSrc::options(), array(
 <span style="white-space:pre"> </span>'id' => 'task-order-src-id',
 ));
 echo $form->dropDownList($model, 'src_shop_id', array(''=>'全部'), array(
 <span style="white-space:pre"> </span>'id' => 'task-shop-id',
 ))
?>

Copy after login

In this code, OrderSrc_options() first reads a drop-down menu. Call the options method in the OrderScr model. The content is as follows

public static function options($hasShop = true) {
 $model = new self();
 if($hasShop) $model->hasShop();
 $models = $model->findAll();
 $array = array(''=>'全部');
 foreach($models as $model) {
 $array[$model->src_id] = $model->src_name;
 }
 return $array;
}

Copy after login

2. Then add JS code to the template page to assign content to the second drop-down menu when the first drop-down menu changes.

<script type='text/javascript'>
$().ready(function(e) {
 $('#task-order-src-id').change(function(e) {
 refreshShops();
 });
 refreshShops();
 function refreshShops() {
 $.get('<?php echo $this->createUrl('getShops')?>', {
  'srcId': $('#task-order-src-id').val()
 }, function(html_content) {
  $('#task-shop-id')
  .html(html_content)
  .find('option[value=<?php echo $model->src_shop_id?>]')
   .attr('selected', 'selected');
 });
 }
});
</script>

Copy after login

In this JS code, a program is called to obtain the value of the second drop-down menu (call the actionGetShops method in the Controller), and any value is appended to the second drop-down menu.

The actionGetShops method in Controller is as follows:

public function actionGetShops() {
 $srcId = $_GET['srcId'];
 $array = ThirdpartInterfaceConfig::options($srcId);
 $htmlContent = "<option value=''>全部</options>";
 foreach($array as $k=>$v) {
 $htmlContent .= "<option value='{$k}'>{$v}</option>";
 }
 echo $htmlContent;
}
Copy after login

How to use drop-down menu to filter in yii framework

Use ajax to send the selected data to the controller, and obtain the results and display them on the view

How to make a drop-down menu in yii, it is not linked to the second level, it is the kind that if I want to send an email to someone, I can have a drop-down menu to choose who I want to send it to

Use ajax and trigger the onchange event to submit

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/854353.htmlTechArticleYii's method of implementing cascading drop-down menus, yii's implementation of drop-down menus This article details how yii's implementation of cascading drop-down menus Method, the specific steps are as follows: 1. Add the following code to the template: php ec...
Statement of this Website
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 Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Yii3 framework in php? How to use Yii3 framework in php? May 31, 2023 pm 10:42 PM

How to use Yii3 framework in php?

How to use PHP framework Yii to develop a highly available cloud backup system How to use PHP framework Yii to develop a highly available cloud backup system Jun 27, 2023 am 09:04 AM

How to use PHP framework Yii to develop a highly available cloud backup system

Yii2 vs Phalcon: Which framework is better for developing graphics rendering applications? Yii2 vs Phalcon: Which framework is better for developing graphics rendering applications? Jun 19, 2023 am 08:09 AM

Yii2 vs Phalcon: Which framework is better for developing graphics rendering applications?

Data query in Yii framework: access data efficiently Data query in Yii framework: access data efficiently Jun 21, 2023 am 11:22 AM

Data query in Yii framework: access data efficiently

Symfony vs Yii2: Which framework is better for developing large-scale web applications? Symfony vs Yii2: Which framework is better for developing large-scale web applications? Jun 19, 2023 am 10:57 AM

Symfony vs Yii2: Which framework is better for developing large-scale web applications?

How to convert yii objects into arrays or directly output to json format How to convert yii objects into arrays or directly output to json format Jan 08, 2021 am 10:13 AM

How to convert yii objects into arrays or directly output to json format

Yii2 Programming Guide: How to run Cron service Yii2 Programming Guide: How to run Cron service Sep 01, 2023 pm 11:21 PM

Yii2 Programming Guide: How to run Cron service

Form builder in Yii framework: building complex forms Form builder in Yii framework: building complex forms Jun 21, 2023 am 10:09 AM

Form builder in Yii framework: building complex forms

See all articles