なぜYii::$app->request->post()
が機能しないのですか?Yii2の投稿リクエストの値が正しく機能しない
フォーム:
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'parent')
->dropDownList($model->AuthItemDropdown
);
?>
<?= $form->field($model, 'child[]')
->dropDownList($model->AuthItemDropdown,
['multiple'=>'multiple']
);
?>
コントローラー:
public function actionCreate(){
$model = new AuthItemChild();
if ($model->load(Yii::$app->request->post())){
$parent = Yii::$app->request->post('parent');
echo $parent; // show nothing
$x = Yii::$app->request->post('child');
print_r($x);// show nothing
exit;
しかしprint_r(Yii::$app->request->post());
の出力です:
print_r(Yii::$app->request->post());
出力に基づいて
Array
(
[_csrf-backend] => OGd0emxoOHgJEh8ICFloPlYvJg8BEHk.VjVAMx0hTD9CKgIDNSdVOg==
[AuthItemChild] => Array
(
[parent] => admin
[child] => Array
(
[0] => admin
[1] => create-branch
)
)
)
とどのよう名を決定私は '子ども 'を数えることができますか? –
'count($ authItemChild ['child'])' – Bizley
これはうまく動いていますが、yii公式ドキュメントは正しい方向から取り除きます[ここ](http://www.yiiframework.com/doc-2.0) /guide-runtime-requests.html)、実際の解決策は異なります。 –