Answer the question
In order to leave comments, you need to log in
(Yii2) How to get the id of the post the user visits?
I need to open access to users only to those posts to which they themselves created.
To do this, I created the post_creator field in the database and write down the author's name there.
When a user clicks on one of the posts from the list, a check should be made to see if its name matches the name in the creator field.
How to get the id of the field that the user clicks on?
Answer the question
In order to leave comments, you need to log in
Hmm .. and so?
$post = Yii::$app->getRequest()->post('postId');
$query = new Query;
$query->select('post_creater')->from('post')->where(['postId'=>$post ]);
$rows = $query->all();
if ($rows['post_creater'] === Yii::$app->user->id) {
echo 'Пользователь создатель поста';
} else {
echo 'Недостаточно прав';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question