Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is my example program from the given link (<a href="http://www.yiiframework.com/wiki/24/" rel="nofollow">http://www.yiiframework.com/wiki/24/</a>)</p> <pre><code> &lt;!-- ===================== My First Dropdown =========== --&gt; &lt;?php echo CHtml::dropDownList('country_id', '', array(1 =&gt; 'USA', 2 =&gt; 'France', 3 =&gt; 'Japan'), array( 'ajax' =&gt; array( 'type' =&gt; 'POST', //My method type 'url' =&gt; CController::createUrl('site/CallCities'), //This is my request/ajax URL array('coountry_id'=&gt;'js:this.value'), //I'm passing the selected dropdonw value. 'dataType' =&gt; 'JSON', 'success'=&gt;'js:function(data)' //The functionaliy after success . '{' . ' var html="";' . ' $.each(data,function(i,obj)' . ' {' . ' html+="&lt;option value=obj.id&gt;"+obj.name+"&lt;/option&gt;"' . ' });' . ' $("#city_id").html(html);' . '}' ))); ?&gt; &lt;!-- ===================== My Second Dropdown =========== --&gt; &lt;?php echo CHtml::dropDownList('city_id', '', array()); ?&gt; </code></pre> <p>And, my controller method is </p> <pre><code> public function actionCallCities() { $cityId=$_POST['coountry_id']; $criteria=new CDbCriteria(); $criteria-&gt;select=array('id,name'); $criteria-&gt;condition='city_id='.$cityId; $criteria-&gt;order='name'; $cityAry= MyCity::model()-&gt;findAll($criteria); $ary=array(); foreach($cityAry as $i=&gt;$obj) { $ary[$i]['id']=$obj-&gt;id; $ary[$i]['name']=$obj-&gt;name; } echo json_encode($ary); } </code></pre> <p>I hope, this example program will work for you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload