你好,我是新为易的框架。我正在创建两个基于第一个下拉的动态下拉列表,我想显示第二个下拉列表。同时,我也想对这两个下拉列表进行验证。那么,如何将id从表单传递到控制器,以及如何对其进行验证?请帮我一下我的表格代码是
echo CHtml::activeDropDownList($model,'classid',CHtml::listData(Classdetails::model()->findAll(array("condition"=>"classid >0 and School_Id='$School' and Status=1","order"=>"classid")),'classid','classname'),
array(
'empty'=>'--Select a Class--',
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('Ptempnotification/Dynamiccities'),
'update'=>'#pid',
)));
echo $form->error($model,'classid');
echo $form->labelEx($model,'pid');
echo CHtml::dropDownList('pid','', array());
echo $form->error($model,'pid');
我的控制器代码是
public function actionDynamiccities()
{
$data = Puserprofile::model()->findAllByAttributes(array('classid' => $_POST['classid']));
$data=CHtml::listData($data,'pid','username');
foreach($data as $value=>$name)
{
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($name),true);
}
}
这里动态城市函数正在调用,但$_POST['classid']
传递的是null。Iam使用yii框架1.1
发布于 2015-03-26 06:30:39
请像这样试试,
echo CHtml::activeDropDownList($model,'classid',CHtml::listData(Classdetails::model()->findAll(array("condition"=>"classid >0 and School_Id='$School' and Status=1","order"=>"classid")),'classid','classname'),
array(
'empty'=>'--Select a Class--',
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('Ptempnotification/Dynamiccities'),
'data'=>array('classid'=>'js: $(this).val()'),
'update'=>'#pid',
)));
https://stackoverflow.com/questions/29272201
复制相似问题