Answer the question
In order to leave comments, you need to log in
How to get a certain status in the grid?
There is a database of personal messages {pm} id, user_id(message to whom), sender_id(who sends) and
status
self::STATUS_UNREAD => 'Unread', 0
self::STATUS_READ => 'Read', 1
self::STATUS_DELETE = > 'Deleted', 2
When the user enters the messages, he sees a list of people who sent him messages, I display them through the Gridview
with this request
$query = self::find()->where('
user_id = :user_id AND sender_id != :user_id AND status != :status',
[
'user_id' => Yii::$app->user->id,
'status' => Pm::STATUS_DELETE,
])
->groupBy('sender_id')
->with(['profile'])
->orderBy('id DESC');
[
'class' => 'yii\grid\ActionColumn',
'headerOptions' => ['width' => '50'],
'template' => '{view} {delete}',
'buttons' => [
'view' => function ($url, $data)
{
$icon = $data->status == 0 ? '<i class="fa fa-envelope"></i>' : '<i class="fa fa-envelope-o"></i>';
return Html::a($icon, ['view', 'id' => $data->sender_id]);
},
'delete' => function ($url, $data)
{
return Html::a('<i class="fa fa-trash"></i>', ['delete', 'id' => $data->sender_id], ['data' => ['confirm' => 'Вы уверены?']]);
},
],
],
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question