Здравствуйте. Использую этот: http://des1roer.blogspot.ru/2016/01/yii ... pdrop.html
Вопрос, в примере показано, что поле имя нужно вводить. Вопрос, а как сделать, чтобы имя также подгружалось динамически? т.е. это не форма будет... пробую по разному, никак не получается. зараннее спасибо))
Завсимы select
Re: Завсимы select
http://demos.krajee.com/widget-details/depdrop вот, я так понял похожее, но не могу понять, как с ним работать... а именно структура базы данных какая допустим для этого: https://c2n.me/3S4HiEH
П.с. делаю это https://c2n.me/3S4Hjzn))
П.с. делаю это https://c2n.me/3S4Hjzn))
Re: Завсимы select
Вот как я пытался делать:
https://c2n.me/3S4HNov
https://c2n.me/3S4HNKy
вид:
Контроллер:
страница относится к actionView. Можете объяснить что именно не так делать? сейчас работает, что-то подгружает, но не правильно все...
https://c2n.me/3S4HNov
https://c2n.me/3S4HNKy
вид:
Код: Выделить всё
<?php
$form = ActiveForm::begin([
'method' => 'post',
'action' => ['controller/action'],
]);
$catList2 = \app\models\Droptest::find()->where('id != cat')->all();
$catList2 = ArrayHelper::map($catList2, 'id', 'name');
echo $form->field($model, 'name')->dropDownList($catList2, ['id' => 'cat-id', 'prompt' => '']); ?>
<?//= $form->field($model, 'name') ?>
<?php
$catList = \app\models\Dropdown::find()->where('id = drop_id')->all();
$catList = ArrayHelper::map($catList, 'id', 'name');
echo $form->field($model, 'cat')->dropDownList($catList, ['id' => 'cat-id', 'prompt' => '']);
if (!$model->isNewRecord && isset($model->cat))
{
$subcatList = \app\models\Dropdown::find()->where('id != drop_id and drop_id = :id', [':id' => $model->cat])->all();
$subcatList_ = ArrayHelper::map($subcatList, 'id', 'name');
if (isset($model->subcat))
{
$subcatList = [$model->subcat => $model->subcats->name];
unset($subcatList_[$model->subcat]);
$subcatList = $subcatList + ['' => 'Выберите...'];
}
else
{
$subcatList = ['' => 'Выберите размер...'];
}
$subcatList = $subcatList + $subcatList_;
}
else
$subcatList = [];
echo $form->field($model, 'subcat')->widget(DepDrop::classname(), [
'options' => ['id' => 'subcat-id'],
'data' => $subcatList,
'pluginOptions' => [
'depends' => ['cat-id'],
'placeholder' => 'Выберите размер...',
'url' => Url::to(['subcat/subcat'])
]
]);
ActiveForm::end();
?>
Код: Выделить всё
public function actionView($granit){
$product = Product::findOne(['alias' => $granit]);
if(empty($product)){
throw new \yii\web\HttpException(404, 'Такого товара нет.');
}
$model = new Droptest();
$this->setMeta($product->title, $product->keywords, $product->description);
return $this->render('view', compact('product', 'model'));
}
public function actionSubcat()
{
$out = [];
if (isset($_POST['depdrop_parents']))
{
$parents = $_POST['depdrop_parents'];
if ($parents != null)
{
$cat_id = $parents[0];
$catList = \app\models\Dropdown::find()->where('drop_id = :id and id != drop_id', [':id' => $cat_id])->all();
$out = ArrayHelper::map($catList, 'id', 'name');
$result = [];
$tmp_arr = [];
foreach($out as $key => $value)
{
$tmp_arr = ['id' => $key, 'name' => $value];
$result[] = $tmp_arr;
}
echo Json::encode(['output' => $result, 'selected' => '']);
return;
}
}
echo Json::encode(['output' => '', 'selected' => '']);
}
Re: Завсимы select
уже разовбрался.