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!!





Probably not related, but "c:/testtest.txt" should be "c:testtest.txt" because Windows.
– kerbholz
Aug 21 at 9:26


"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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)