On the view side:
<?php echo $form->labelex ($model, ' test '); ?> <?php echo chtml::d ropdownlist (' Province ', ', ', Array (' Province ', 1=> ' Guangdong ', 2=> ' Guangxi '), array ( ' ajax ' = >array ( ' type ' = ' POST ', ' URL ' =>yii::app ()->createurl (' site/ Getcity '), ' update ' = ' #city ', ' data ' =>array (' province ' = ' js:$ ' ( "#province"). Val () '), ) ); ?> <?phpecho chtml::d ropdownlist (' City ', ' ", Array (' City ')) ;? >
On the controller side
Public Function actiongetcity () {if (! Yii::app ()->request->isajaxrequest) throw new chttpexception (404); $province = (int) $_post[' province ']; $data =array (1=>array (1=> ' Guangzhou ', ' Shenzhen ', ' Dongguan ', ' Foshan '), 2=>array (1=> ' Guilin ', ' nanning ', ' Yulin ')); if (Isset ($data [$province])) {foreach ($data [$province]as$value=> $name) {echo chtml::tag (' option ', Array (' value ' = > $value), Chtml::encode ($name), true); }}else{Echo chtml::tag (' option ', Array (' value ' = = '), ' city ', true); } }
This article is from the "Java White Battlefield" blog, be sure to keep this source http://8023java.blog.51cto.com/10117207/1748803
Cactiveform DropDownList linkage effect in the YII framework of PHP