【问题标题】:how to get post value from multiple array in yii2如何从yii2中的多个数组中获取post值
【发布时间】:2016-01-11 08:46:10
【问题描述】:

我想在 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] => 
                )

        )

我试图通过以下函数获取价值,但我无法获取它。

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

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

如何获取名称数组的值? 我不想像 $_POST['Brand']['name'][0] 那样使用它,我只需要使用 yii2 函数

【问题讨论】:

    标签: yii2 yii2-advanced-app


    【解决方案1】:

    尝试使用ArrayHelper class

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

    $request->post() 方法的工作方式,它只是返回一个来自$_POST 的值,所以用法是:

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

    【讨论】:

    • Array ( [total_images] => 4 [images_uploaded] => 1 ) 这两个值可以从同一个方法返回吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-27
    • 1970-01-01
    • 2017-12-29
    • 2021-06-06
    相关资源
    最近更新 更多