tz_com 2011-03-28 16:14:42 4346次浏览 0条回复 0 0 0

如题,请教 代码如下: _form中

<?php
echo $form->dropDownlist($channel, 'channel_parent_id', Channel::channels(),
array(
  'ajax' => array(
  'type' => 'POST', //request type
  'url' => Yii::app()->createUrl('Channel/Dynamiccities'),
  'update' => '#Channel[channel_id]', //selector to update
  //'data'=>'js:javascript statement'
  //leave out the data key to pass all form values through
)));
echo CHtml::dropDownList('Channel[channel_id]', '', array("请先选择国家")); ?>

Channelcontroller中:

public function actionDynamiccities() {
  $parent_id = (int) $_POST['Channel']['channel_parent_id'];
  $data = Location::model()->findAll('channel_parent_id=:parent_id',
  array(':parent_id' => $parent_id));
    if (!isset($data))
    $data = array(
    array("id" => 0, "name" => "请先选择国家"),
  );
  $data = CHtml::listData($data, 'id', 'name');
  foreach ($data as $value => $name) {
    echo CHtml::tag('option',
    array('value' => $value), CHtml::encode($name), true);
  }
}
    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册