DepDrop in yii2 not work?
DepDrop in yii2 not work?
I'm using DepDrop for dependency Dropdownlist. for this, I've written follow codes:
in view form:
use kartikdepdropDepDrop;
$catList = ['1' => 1, '2' => 2];
echo $form->field($model, 'cat')->dropDownList($catList, ['id' => 'cat-id']);
// Child # 1
echo $form->field($model, 'subcat')->widget(DepDrop::classname(), [
'options' => ['id' => 'subcat-id'],
'pluginOptions' => [
'depends' => ['cat-id'],
'placeholder' => 'Select...',
'url' => yiihelpersUrl::to(['/faculty/list']),
],
]);
Controller:
public function actionList()
$out = ;
if (isset($_POST['depdrop_parents']))
$parents = $_POST['depdrop_parents'];
if ($parents != null)
$cat_id = $parents[0];
$out = [
['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' => '']);
but it doesn't work. I found out that actionList is't called by include follow code at the first of actionList function.
file_put_contents("c:/testtest.txt", implode(',',$_POST));
file_put_contents("c:/testtest.txt", implode(',',$_POST));
and this is head of request:
Request URL: http://admin.same.ir/index.php?r=faculty/list
Request Method: POST
Status Code: 400 Bad Request
Remote Address: 127.0.0.1:80
Referrer Policy: no-referrer-when-downgrade
I don't know what is the problem!!
"c:/testtest.txt"
"c:testtest.txt"
No. I've just wanted to say that the function is not called.
– Rahman
Aug 21 at 9:30
1 Answer
1
it was just for CSRF:
I added follow code to controller:
public $enableCsrfValidation = false;
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Probably not related, but
"c:/testtest.txt"
should be"c:testtest.txt"
because Windows.– kerbholz
Aug 21 at 9:26