get content of current user

Is it possible to display in view all posts created by current login user

I already created create view for post with model and controller, I have view for single post and index that show all posts

But I want to create a view for posts created by the current login user the view name is myPost

Thank you

It’s fairly easy.

Your "my-post" page will be almost the same as the "index" page. The difference is that you fix the owner of the post in the search model to the current user.




public function actionMyPost()

{

    $searchModel = new PostSearch;

    $searchModel->createdBy = Yii::$app->user->identity->id;

    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

    return $this->render('my-post', [

        'searchModel' => $searchModel,

        'dataProvider' => $dataProvider,

    ]);

}



The "search" method of the search model will filter the result by the owner of the post.

Thank you so much