互相影响的选择

models
public function getLists($company_id = ''){
		$companye_model = Company::model()->findByPk($company_id);
		
		if($companye_model){
			$model = $this->model()->findAll(array(
					'condition' => 'pid=:pid',
					'params' 	=> array(':pid'=>$companye_model->id),
			));
		}else{
			$model = $this->model()->findAll();
		}

		if(is_null($model))
			return  null;

		$data = array();
		foreach ($model as $key => $value) {
			$data[$value->id] = $value->name;
		}
		return $data;
	}
$_form
<div class="row col-xs-8">
		<div class="col-xs-2">
			<?php echo $form->labelEx($model,'pid'); ?>
		</div>
        <div class="col-xs-9">
        <?php echo CHtml::dropDownList('CompanyProduct[pid]','CompanyProduct[pid]', Company::model()->getLists(), array(
            	'class'=>'form-control',
            	'ajax'=>array(
                'type'=>'GET',
                'url'=>CController::createUrl('/companyProduct/getType'),
                'update'=>'#CompanyProduct_typeid',
                'data'=>array('mid'=>"js:this.value",'typeid'=>1)
 
            ))
        ); ?

> </div> </div> <div class="row col-xs-8"> <div class="col-xs-2"> <?php echo $form->labelEx($model,'typeid'); ?

> </div> <div class="col-xs-9"> <?php echo CHtml::activeDropDownList($model,'typeid',ProductType::model()->getLists(),array('class'=>'form-control')); ?> <?php echo $form->error($model,'typeid'); ?> </div> </div>

controller
public function actionGetType($mid){
		$results = ProductType::model()->getLists($mid);
		foreach ($results as $key => $value) {
			echo CHtml::tag('option', array('value'=>$key),CHtml::encode($value),true);
			# code...
		}
	}



posted @ 2017-06-20 11:02  lytwajue  阅读(159)  评论(0编辑  收藏  举报