如何在Yii中使用POST方法建立链接?

Chl*_*loe 4 php yii2

在Rails中我们可以做到

= link_to 'Logout', destroy_user_session_path, method: :post
Run Code Online (Sandbox Code Playgroud)

我们如何在Yii实现这一目标?(无需手动创建隐藏表单:使链接使用POST而不是GET.)

我通过指南看Urlpost,但没有发现任何东西.

http://www.yiiframework.com/doc-2.0/guide-helper-url.html

到目前为止,我有这个

%a.btn.btn-sm.btn-success{href: Url::to(['update-bid', 'change' => 'plus'])} +10%
Run Code Online (Sandbox Code Playgroud)

Chi*_*may 16

试试这个:

<?= Html::a('submit', Url::to(['site/index']), ['data-method' => 'POST']) ?>
Run Code Online (Sandbox Code Playgroud)


Dha*_*ngh 11

用于创建基于链接的Post Link的 Folllow代码

<?= Html::a('Text', 
['/controller/action'], [
'data-method' => 'POST',
'data-params' => [
    'param1' => 1,
    'param2' => 2,
],
]) ?>
Run Code Online (Sandbox Code Playgroud)

然后你可以在控制器中访问这些变量

public function actionAction () {
   $param1 = Yii::$app->request->post('param1', null);
   $param2 = Yii::$app->request->post('param2', null);
}
Run Code Online (Sandbox Code Playgroud)

有关击球手详细信息,请点击以下链接 点击此处