You are really short on details, but I assume you want to display both incoming and sent messages by matching current user ID (logged in user) with both receiver_id and sender_id and display them in a gridview.
An approach could be:
public function actionIndex()
{
$user = Yii::$app->user->identity;
$searchModel = new MesssageSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
// filter on ownership of either sender or receiver
$dataProvider
->query
->andWhere(['receiver_id' => $user->id])
->orWhere(['sender_id' => $user->id]);
$dataProvider->setSort([
'defaultOrder' => ['created_at' => SORT_DESC],
]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
This assumes you have limited access to logged-in users otherwise you need to catch the case when Yii::$app->user is null.