Проблема с выводом данных в зависимую форму. Пользуюсь depDrop widget. При выборе поля первого поля, второе поле бездействует.
Прошу помочь пожалуйста.
VIEW:
Код: Выделить всё
use yii\bootstrap\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use app\models\Games;
use kartik\depdrop\DepDrop;
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($games, 'id')
->dropDownList(
ArrayHelper::map(Games::find()->all(), 'id', 'name'),
['prompt'=>'Выберите игру']
);
?>
<?= $form->field($servers, 'name')->widget(DepDrop::classname(), [
'options' => ['id' => 'name'],
'pluginOptions' => [
'depends' => ['id'], //тут должен писаться id родительской таблицы, я правильно понял?(Или id род.таблицы в дочерней таблице?)
'placeholder' => 'hello from servers',
'url' => \yii\helpers\Url::to(['servers/servers'])
]
]);
?>
<?php ActiveForm::end(); ?>
Код: Выделить всё
public function actionIndex()
{
$games = new Games();
$servers = new Servers();
$customer = new Customer();
return $this->render('index', ['games' => $games, 'servers' => $servers, 'customer' => $customer]);
}
Код: Выделить всё
public function actionServers()
{
$out = [];
if (isset($_POST['depdrop_parents'])) {
$parents = $_POST['depdrop_parents'];
if ($parents != null) {
$game_id = $parents[0];
$out = \app\models\Servers::gelServerList($game_id);
echo Json::encode(['output'=>$out, 'selected'=>'']);
return;
}
}
echo Json::encode(['output'=>'', 'selected'=>'']);
}
Код: Выделить всё
public static function gelServerList($game_id)
{
$query = self::find()
->where(['game' => $game_id, 'is_show' => 1])
->select(['id', 'name'])->asArray()->all();
return $query;
}