Answer the question
In order to leave comments, you need to log in
How to display the number of comments on one post while still displaying who left?
Guys, good time.
I have a question. The task is:
There is a personal account, in the personal account (on the site) there are posts, you can leave comments on these posts.
I display posts and link them to the user's profile.
But I can't figure out how to properly link other users tobish their comments tobish to one post. And display under the post?
The table structure is
comments
user_posts
Then in the code I make relational links to all models
User_profile
User_post
Comments
Here are the links themselves
, then I make a request, I hang up a getter which actually already has comments and a record in it. I pass it to the view. I pick up the user id to verify that this is his entry - a post.
$resultPostUser = UserProfile::find()
->asArray()
->with('posts')
->where(['user_id' => $my_id])
->one();
Answer the question
In order to leave comments, you need to log in
$queryPostUser->from(UserPosts::tableName()." us_post")
->select('us_prof.user_id, us_prof.avatar, user.username, us_post.text, us_post.id, com_us.text as comment')
->leftJoin(UserProfile::tableName()." us_prof",'us_prof.user_id = us_post.id_user')
->leftJoin(User::tableName()." user",'user.id = us_post.id_user')
->leftJoin(Comments::tableName()." com_us",'com_us.id_post = us_post.id')
->where(['us_post.id_user' => Yii::$app->user->identity->getId()]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question