Нужна помощь в DepDrop

Различные вопросы по установке и настройке фреймворка, конфигурции веб-сервера и IDE.
Ответить
Dante161
Сообщения: 1
Зарегистрирован: 2017.02.08, 11:30

Нужна помощь в DepDrop

Сообщение Dante161 »

Доброго времени суток. Помогите разобраться. Поставил DopDrop demos.krajee.com/widget-details/depdrop по третьему сценарию. Но не могу заставить второе и третье поле загружать данные из бд. Постоянно висит надпись Загрузка...
И почему то второе поле стоит активным, его нужно сделать не активным как и третье. скрины ниже.
_form.php:

Код: Выделить всё

<?php

use app\modules\brand\models\AccBrand;
use app\modules\device_type\models\AccDeviceType;
use app\modules\model_of_device\models\AccModelOfDevice;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use kartik\form\ActiveForm;
use kartik\widgets\DepDrop;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $model app\modules\service\models\AccService */
/* @var $form yii\widgets\ActiveForm */
?>

<?php if ($model->isNewRecord) {?>

    <?= $form->field($model, 'brand')->widget(DepDrop::classname(), [
        'id' => 'brand-id',
        'data' => ArrayHelper::map(
            AccBrand::find()->asArray()->all(),
            'id',
            'brand_name'
        ),
        'options' => [
            'placeholder' => 'Select ...'/* ,
          'multiple' => true */
        ],
        'type' => DepDrop::TYPE_SELECT2,
        'select2Options' => ['pluginOptions' => ['allowClear' => true]],
        'pluginOptions' => [
            'depends' => ['brand-id'],
            'url' => Url::to(['/service/child-brand']),
            'loadingText' => 'Загрузка...',
        ]
    ]);
    ?>
    <?= $form->field($model, 'device_type')->widget(DepDrop::classname(), [
        'data' => ArrayHelper::map(
            AccDeviceType::find()->asArray()->all(),
            'id',
            'device_type'
        ),
        'options' => ['placeholder' => 'Select ...'],
        'type' => DepDrop::TYPE_SELECT2,
        'select2Options' => ['pluginOptions' => ['allowClear' => true]],
        'pluginOptions' => [
            'depends' => ['accservice-brand'],
            'url' => Url::to(['/service/child-account']),
            'loadingText' => 'Загрузка...',
        ]
    ]);
    ?>

    <!-- --><?php /* $brand = $this->brand;
      $device_type = $this->device_type;
     */ ?>

    <?=
    $form->field($model, 'model')->widget(DepDrop::classname(), [
        'data' => ArrayHelper::map(
            AccModelOfDevice::find()
                ->where('id_brand_name = :id_brand_name', [':id_brand_name' => $brand])
                ->andWhere('id_device_type = :id_device_type', [':id_device_type' => $device_type])
                ->asArray()
                ->all(),
            'id',
            'model_name'
        ),
        'options' => ['placeholder' => 'Select ...'],
        'type' => DepDrop::TYPE_SELECT2,
        'select2Options' => ['pluginOptions' => ['allowClear' => true]],
        'pluginOptions' => [
            'depends' => ['accservice-device_type'],
            'url' => Url::to(['/service/child-account']),
            'loadingText' => 'Загрузка...',
        ]
    ]);
    ?>

    <?php
}
?>
DefaultController.php:
<?php

Код: Выделить всё

<?php

namespace app\modules\service\controllers;

use app\modules\brand\models\AccBrand;
use app\modules\device_type\models\AccDeviceType;
use app\modules\model_of_device\models\AccModelOfDevice;
use Yii;
use app\modules\service\models\AccService;
use app\modules\service\models\AccServiceSearch;
use yii\helpers\Json;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * DefaultController implements the CRUD actions for AccService model.
 */
class DefaultController extends Controller
{

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * Lists all AccService models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new AccServiceSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * Displays a single AccService model.
     * @param integer $id
     * @return mixed
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

    /**
     * Creates a new AccService model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new AccService();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['update', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

    public function actionChildBrand()
    {
        $out = [];
        if (isset($_POST['depdrop_parents'])) {
            $id = end($_POST['depdrop_parents']);
            $list = AccDeviceType::find()->asArray()->all();
            $selected = null;
            if ($id != null && count($list) > 0) {
                $selected = '';
                foreach ($list as $i => $model) {
                    $out[] = ['id' => $model['id'], 'name' => $model['device_type']];
                    if ($i == 0) {
                        $selected = $model['id'];
                    }
                }
                // Shows how you can preselect a value
                echo Json::encode(['output' => $out, 'selected' => $selected]);
                return;
            }
        }
        echo Json::encode(['output' => '', 'selected' => '']);
    }

    public function actionChildAccount()
    {
        $out = [];
        if (isset($_POST['depdrop_parents'])) {
            $id = end($_POST['depdrop_parents']);
            $list = AccModelOfDevice::find()->
                andWhere(['id_brand_name' => $brand])->
                andWhere(['id_device_type' => $device_type])->
                asArray()->all();
            $selected = null;
            if ($id != null && count($list) > 0) {
                $selected = '';
                foreach ($list as $i => $account) {
                    $out[] = ['id' => $account['id'], 'name' => $account['name']];
                    if ($i == 0) {
                        $selected = $account['id'];
                    }
                }
                // Shows how you can preselect a value
                echo Json::encode(['output' => $out, 'selected' => $selected]);
                return;
            }
        }
        echo Json::encode(['output' => '', 'selected' => '']);
    }

    /**
     * Updates an existing AccService model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Deletes an existing AccService model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();

        return $this->redirect(['index']);
    }

    /**
     * Finds the AccService model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return AccService the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = AccService::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}
таблицы

Код: Выделить всё

CREATE TABLE `acc_brand` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `brand_name` varchar(50) NOT NULL COMMENT 'Бренд',
    `authorization` int(1) DEFAULT NULL COMMENT 'Гарантийный ремонт от производителя',
    `logo_img` varchar(55) DEFAULT NULL COMMENT 'Путьк картинке логотипа',
    PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 AVG_ROW_LENGTH=4096 ROW_FORMAT=DYNAMIC

CREATE TABLE `acc_device_type` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `device_type` varchar(50) NOT NULL COMMENT 'Тип аппарата',
    PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 AVG_ROW_LENGTH=3276 ROW_FORMAT=DYNAMIC COMMENT='Тип аппарата'

CREATE TABLE `acc_model_of_device` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `model_name` varchar(250) NOT NULL,
    `id_brand_name` int(11) NOT NULL,
    `id_device_type` int(11) NOT NULL,
    `model_img` varchar(50) NOT NULL,
    PRIMARY KEY (`id`),
    KEY `model_brand__fk` (`id_brand_name`),
    KEY `model_device_type_id_fk` (`id_device_type`),
    CONSTRAINT `model_brand__fk` FOREIGN KEY (`id_brand_name`) REFERENCES `acc_brand` (`id`),
    CONSTRAINT `model_device_type_id_fk` FOREIGN KEY (`id_device_type`) REFERENCES `acc_device_type` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=cp1251
Ответить