Answer the question
In order to leave comments, you need to log in
How to run the depdrop widget?
I can't run the depdrop widget on yii2 Did according to the documentation demos.krajee.com/widget-details/depdrop
Here is the code that I have frontend/views/site/signup.php
use kartik\depdrop\DepDrop;
use yii\helpers\ArrayHelper;
use frontend\models\Country;
use fronted\models\Region;
<?php
$countryList = Country::find()->wherw('id = country_id')-all();
$countryList = ArrayHelper::map($countryList, 'id', 'name');
?>
<?= $form->field($model, 'country')->dropDownList($countryList, ["id"=>"country_id"]); ?>
<?= $form->field($model, 'region')->widget(DepDrop::classname(), [
'options' => ['id'=>'region_id'],
'pluginOptions'=>[
'depends'=>['country_id'],
'placeholder' => 'Выберите страну',
'url' => Url::to(['/site/region'])
]
]); ?>
class SiteController extends Controller
{
public function actionRegion() {
$out = [];
if (isset($_POST['depdrop_parents'])) {
$parents = $_POST['depdrop_parents'];
if ($parents != null) {
$country_id = $parents[0];
$out = self::getRegionList($country_id);
// the getSubCatList function will query the database based on the
// cat_id and return an array like below:
// [
// ['id'=>'<sub-cat-id-1>', 'name'=>'<sub-cat-name1>'],
// ['id'=>'<sub-cat_id_2>', 'name'=>'<sub-cat-name2>']
// ]
echo Json::encode(['output'=>$out, 'selected'=>'']);
return;
}
}
echo Json::encode(['output'=>'', 'selected'=>'']);
}
}
namespace frontend\models;
use yii\db\ActiveRecord;
class Country extends ActiveRecord
{
}
Answer the question
In order to leave comments, you need to log in
Good morning.
You are the text of the error, for starters, translate and correct it, then you will move on.
PS
Have you looked at the examples in the widget's documentation? Did you see grid there?
By specifying the address /site/region, you firstly refer to the SiteController controller, and secondly, to the action of this actionRegion controller.
You need to get the data of all regions from the database.
To do this, just go to the database and get the regions. From this object, widget will create a dropdown list on the form.
Explained as best I could.
PSS If you do not know the bourgeois language, then good google took care of it, there are automatic translators, the first one is at translate.google.com, the second one you can find in the google-chrome browser store .
Use either the first one or install the browser extension.
This is the first.
Second.
Open the widget's documentation and translate the text with the help of a translator, trying to figure it out.
Consider the "url" parameter
The documentation says:
Yeah, we translate with a translator
Here, we met some unknown ajax beast. And in addition json... It's not clear... Okay, let's see examples...
And in the example we find the line
echo Json::encode(['output'=>$data['out'], 'selected'=>$data['selected']]);
return;
/**
* the getProdList function will query the database based on the
* cat_id and sub_cat_id and return an array like below:
* [
* 'out'=>[
* ['id'=>'', 'name'=>' '],
* ['id'=>'', 'name'=>'']
* ],
* 'selected'=>''
* ]
*/
getProdList function will query the database based on
*cat_id and sub_cat_id and return an array like below:
the error clearly indicates
$countryList = Country::find()->wherw('id = country_id')-all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question