M
M
Messi2017-10-20 13:21:55
Yii
Messi, 2017-10-20 13:21:55

How to display the name instead of the model?

Tell me, please, the logic:
I am writing a simple event log.
There is a table log (id, model_name, model_id, action, created_at)
Model_name - the full name of the model (entity) class with namespace is stored here, for example common\User
Model_id - id of the changed entity.
Now there are two models that we log.
User and Staff
In the Log table, I registered connections by log.model_id = id (here is the main question)
Now, when changing, for example, in user and staff, the log table has data
1 \common\User 2 update 243334
2 \common\Staff 4 create 277473
Everything is fine, but I need to display everything recorded in the logs in the gridview.
Initially, the gridview goes
Id Action Created_at
Model_name
Model_id
Here is the question, how can I display the name of the model record instead of model_id, depending on the model name?
So that the gridview table would look like this:
1 \common\User John edit 293949
2 \common\Staff Director delete 283848

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-10-20
@FitTech

Good afternoon.
By connection name.

$model->name_relation->name // name_relation имя связи в модели.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question