2016-03-20 13 views
1

Kullanıcının arayacağı bir filtre oluşturmak istiyorum. Bu bağımlı açılan listeyi oluşturuyorum ama işe yaramıyor. 'Şehir' ve 'eyalet' tablolarım var. Bu calismiyor. HATA 0/Yii2: Bağımlılık Açma Listesi öğesini aramak için

Birisi bana nerede yanlış gittiğimi söyleyebilir mi? Teşekkürler. senin Onchange $ .post yolunda sonrası kontrolörü

public function actionLists($id) 
    { 
    $countPosts = States::find() 
    ->where(['city_id' => $id]) 
    ->count(); 

    $posts = States::find() 
    ->where(['city_id' => $id]) 
    ->orderBy('id DESC') 
    ->all(); 

    if($countPosts>0){ 
    foreach($posts as $post){ 

    echo "<option value='".$post->id."'>".$post->name."</option>"; 
    } 
    } 
    else{ 
    echo "<option>-</option>"; 
    } 

cevap

1

yılında

Benim formu

<?php 
$dataCity=ArrayHelper::map(\app\models\Cities::find()-> 
asArray()->all(),'id', 'name');  
       $form = ActiveForm::begin(); 
      echo $form->field($searchModel, 'id')->dropDownList($dataCity, 
           [''=>'-Choose a Name-', 
            'class'=>'adjust', 
         'onchange'=>' 
     $.post("index.php?r=post/lists?id='. 
     '"+$(this).val(),function(data) 
       { 
          $("select#post").html(data); 
         }); 
        ']); 

      $dataState=ArrayHelper::map(\app\models\States::find()-> 
      asArray()->all(), 'id', 'name'); 
      echo $form->field($searchModel, 'id') 
       ->dropDownList(
        $dataState, 
        ['id'=>'name', 
         'class'=>'adjust' 
         ] 
       ); 
      ActiveForm::end(); 
      ?> 

Listem eylem ikinci GET parametresi ? ile & değil bu şekilde `endeks başlamalıdır. php? r = gönderi/listeler & kimlik

'onchange'=>' 
    $.post("index.php?r=post/lists&id='. // use & not ? 
    '"+$(this).val(),function(data) 
      { 
         $("select#post").html(data); 
        }); 
       ' 
+0

Teşekkür ederiz:) İşe yarıyor – Starite