How to send message options from yii2 gridview

I am new to yii2. I am trying to send some parameters to an action from a view using the post method, unfortunately my action does not seem to see / accept them. Help will be appreciated.

my column action looks something like this:

'buttons'=> [
    'password'=> function ($url, $model, $key){
    $url =$url = Url::toRoute(['users/reset-password', 'username' => $model->username]);
    return Html::a('<span class="glyphicon glyphicon-asterisk"></span>',$url,[
                   'title'=>'Clave',
                   'data-confirm' => Yii::t('yii', 'Are you sure you want to change this password?'),
                   'data-method' => 'post',
                   'data' => ['username'=>$model->username, 'test-name'=>'this is just for testing'],
                        ]);
                },
.....

everything in the data parameter should be mailed, but I only get the csrf token. in advance for help.

+4
source share
3 answers

use below code

echo Html::a('Name', ['controller/action'], [
    'class'=>'classname',
    'data'=>[
        'method'=>'post',
        'confirm'=>'Are you sure? OK to continue Retract..',
        'params'=>[
            'param1'=>'value',
            .......,
        ],
    ]
]);
+7
source

" ", ? - , - "" .
:

  • get OR
  • . .
+2

Try sending a session:

'buttons'=> [<br/>
    'password'=> function ($url, $model, $key){<br/>
     Yii::$app->session->set('username',$model->username);<br/>
     Yii::$app->session->set('test-name','this is just for testing');<br/>
    $url =$url = Url::toRoute(['users/reset-password', 'username' => $model->username]);<br/>
    return Html::a('<span class="glyphicon glyphicon-asterisk"></span>',$url,[<br/>
                   'title'=>'Clave',<br/>
                   'data-confirm' => Yii::t('yii', 'Are you sure you want to change this password?'),<br/>
                   'data-method' => 'post',<br/>

                        ]);
                },

On Controller will call this:

You can get a session:

Yii::$app->session->get('username');

And delete the session

Yii::$app->session->remove('username');
0
source

Source: https://habr.com/ru/post/1568959/


All Articles