Зависимые поля в yii Пример 2

views form

<div class="row"> <?php echo $form->labelEx($model,'department_id'); ?> <?php //echo $form->textField($model,'department_id'); ?> <?php // TODO: Попробоват заменить GetDepartmentsList на CHtml::listData() echo $form->dropDownList($model,'department_id',$model->GetDepartmentsList(), array( 'empty'=>'- select -', //'options' => array(Yii::app()->request->getQuery('id')=>array('selected'=>true)), 'ajax' => array( 'type'=>'POST', //request type 'url'=>EsCore::url('performers'), //url to call. //Style: CController::createUrl('currentController/methodToCall') 'update'=>'#performer', //selector to update //'data'=>'js:javascript statement' //leave out the data key to pass all form values through ) ) );?> <?php echo $form->error($model,'department_id'); ?> </div> Выбор пользователей согласно отделу (комбобокс) <div class="row"> <?php echo $form->labelEx($model,'performer'); ?> <?php //echo $form->textField($model,'performer'); ?> <?php //echo $form->dropDownList($model,'category',$model->GetUsersList(), array('empty'=>'- select -', 'options' => array(Yii::app()->request->getQuery('id')=>array('selected'=>true))));?> <?php echo CHtml::dropDownList('performer','',array(),array('prompt'=>'PleaseSelect'));?> <?php echo $form->error($model,'performer'); ?> </div>

controller

public function actionPerformers() { $values = $_POST['Offers']; $models = YumUser::model()->with('profile')->findAll('profile.department_id = :id', array(':id' => (int)$values['department_id']));; //$model=CHtml::listData($model,'id','id'); foreach ($models as $id=>$model) { $name = $model->profile->firstname . ' ' . $model->profile->lastname; echo CHtml::tag('option',array('value'=>$model->id),CHtml::encode($name),true); } }