php - Dependent Dropdown internal server error(500) -
i found question in stackoverflow.but getting different error. try trying implement dependent dropdown in yii. values getting database first dropdown. can't resultant output in second dropdown.
controller:
public function actiondynamic(){ $data=stu::model()->findall('sna=:parent_id', array(':parent_id'=>$_post['sna'])); // var_dump($data); // exit(); $data=chtml::listdata($data,'branch','branch'); // var_dump($data); // exit(); foreach($data $value=>$name){ echo chtml::tag('option', array('value'=>$value),chtml::encode($name),true); } }
view:
<div class="row"> <?php echo $form->labelex($model,'sna'); ?> <?php $snaarray = chtml::listdata(stu::model()->findall(),'sna','sna'); echo $form->dropdownlist($model,'sna',$snaarray, array( 'ajax' => array( 'type'=>'post', 'url'=>ccontroller::createurl('stu/dynamic'), 'update'=>'#branch'))); ?> <?php echo $form->error($model,'sna'); // var_dump($snaarray); // exit(); ?> </div> <div class="row"> <?php echo $form->labelex($model,'branch'); ?> <?php echo chtml::dropdownlist('branch','', array(), array('prompt'=>'select branch')); ?> <?php echo $form->error($model,'branch'); ?> </div>
table:
sid int sna varchar(25) branch varchar(5)
i followed link http://www.yiiframework.com/wiki/24/ achieve dependent dropdown
it doesn't show errors. in network tab(f12 key) change first dropdown showing "http://localhost:8080/student/index.php?r=stu/dynamic" 500(internal server error).
please me in advance.
problem here
$_post['sna']
in ajax call post data go in form of yourmodel[property]
ex: stu['sna'] stu['some_other']
so, in action dynamic $_post['sna']
cannot pick posted value
change:
$data=stu::model()->findall('sna=:parent_id', array(':parent_id'=>$_post['sna']));
to
$data=stu::model()->findall('sna=:parent_id', array(':parent_id'=>$_post['stu']['sna']));
or
public function actiondynamic() { $postvalues=$_post['stu']; $data = stu::model()->findall('sna=:parent_id', array(':parent_id' =>$postvalues['sna'] )); $data = chtml::listdata($data, 'sna', 'sna'); foreach ($data $value => $name) { echo chtml::tag('option', array('value' => $value), chtml::encode($name), true); } }
Comments
Post a Comment