简体   繁体   English

如何从yii2中的多个数组中获取post值

[英]how to get post value from multiple array in yii2

I want to get value of post array in yii2, I have array like this 我想在yii2中得到post数组的值,我有这样的数组

[Brand] => Array
                (
                    [name] => Array
                        (
                            [0] => testing
                            [1] => jkhkjhjkhjk
                        )

                    [tagline] => Array
                        (
                            [0] => kjhjkh
                            [1] => 
                        )

                    [meta_keyword] => Array
                        (
                            [0] => 
                            [1] => 
                        )

                    [sort_order] => 
                    [image] => brand/1452498338552.jpg
                    [status] => 
                )

        )

I tried to get value with below function, but i am unable to get it. 我试图通过以下功能获得价值,但我无法得到它。

$request = Yii::$app->request;

$request->post('Brand[name][0]');

How can i get value of name array ? 我怎样才能获得名称数组的价值? I don't want to use it like $_POST['Brand']['name'][0], I need to use only yii2 function 我不想像$ _POST ['Brand'] ['name'] [0]那样使用它,我只需要使用yii2函数

Try to use ArrayHelper class 尝试使用ArrayHelper类

$var = ArrayHelper::getValue($request->post(), 'Brand.name.0');

The way $request->post() method works, it just returns to you a value from $_POST , so usage is: $request->post()方法的工作方式,它只返回$_POST的值,因此用法为:

$brand = $request->post('Brand'); // now $brand variable contains $_POST['Brand']
$var = $brand['name'][0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM