【发布时间】:2018-08-21 09:24:17
【问题描述】:
我正在使用 DepDrop 作为依赖项下拉列表。为此,我编写了以下代码:
在视图中:
use kartik\depdrop\DepDrop;
$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' => \yii\helpers\Url::to(['/faculty/list']),
],
]);
控制器:
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' => '']);
}
但它不起作用。我发现在actionList函数的第一个包含跟随代码没有调用actionList。
file_put_contents("c:/testtest.txt", implode(',',$_POST));
这是请求的负责人:
请求网址:http://admin.same.ir/index.php?r=faculty/list
请求方法:POST
状态码:400 错误请求
远程地址:127.0.0.1:80
推荐人政策:no-referrer-when-downgrade
不知道是什么问题!!
【问题讨论】:
-
可能不相关,但
"c:/testtest.txt"应该是"c:\testtest.txt"因为 Windows。 -
没有。我只是想说这个函数没有被调用。