S
S
Stepan2015-01-29 12:46:15
Yii
Stepan, 2015-01-29 12:46:15

(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

1 answer(s)
M
melnikov_m, 2015-01-29
@melnikov_m

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 question

Ask a Question

731 491 924 answers to any question