简体   繁体   中英

Send post array via yii2 Html a()

When i'm trying to send array User via Yii Html a

echo Html::a('Text',
    ['/user/admin/create'], [
        'data' => [
            'method' => 'post',
            'params' => [
                'User' => [
                 'name' => 'qwe',
                ],
            ],
        ],
    ])

I'm getting

$_POST['User'] = '[object Object]'

yes it's STRING!

help please

If you need to pass an array you may use following construction:

<?= Html::a('Link Text', ['/user/admin/create'], [
    'data'=>[
        'method' => 'post',
        'params'=>[
            'User[name]' => 'John',
            'User[age]' => '25',
        ],
    ]
]) ?>

Also you can define onclick property for link and pass you own javascript handler for request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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