Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get the key Id from the grid #16

Open
sundown11 opened this issue Apr 19, 2020 · 1 comment
Open

How can I get the key Id from the grid #16

sundown11 opened this issue Apr 19, 2020 · 1 comment

Comments

@sundown11
Copy link

Hi,

I am really new to Yii2 and I want to understand how I can obtain the DB table key for the value modified. The controller action is receiving the post ok , but I only have the changed variable., not the DB key to modify. How do I do this?

Nick

@mfrattola
Copy link

mfrattola commented Jun 23, 2021

I don't know if you still need this answer, but I can share with you what I did.

In the column definition, I used a callable to build a url with parameters, like this:
[ 'class' => EditableColumn::class, 'attribute' => 'name-of-attribute', 'url' => ['change'], 'editableOptions' => function($model, $key, $index ) : array { return ['url'=>'change?id=$model->key]; } ],

where key is the key-field of the model

Then your action needs to define a parameter like this:

public function actionChange($id)

and within the action you can retrieve the model and validate, change the value of the attribute, and save.

Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants