Answer the question
In order to leave comments, you need to log in
How to pass user id to view?
Good evening! I have a site that has a profile system. All ajax is releasing a js file, where there is the following function:
function getUserPosts(user_id) {
$.ajax("/api/user/5/posts", {
type: "GET",
....
Answer the question
In order to leave comments, you need to log in
You have a Profile controller and an actionView. You need to get Yii in it: $app->user->identify-getId()
Then search the database for its data by id.
If the posts need to be received by the current user, then the user_id does not need to be passed. You need to get it as written above.
I don't understand what is the problem? The question is a little unclear.
Yii:$app->user->identify-getId() gets the id of the current user. I'll explain in more detail. I need dynamics, ajax, that is. I made api as a module, through ajax (js script) I access it. There is a conditional variable user_id - the id of the user whose profile we are looking at, is responsible for the operation of the functions to actually receive a post, like, comment, etc. Actually, we can be on our profile. I realized that the question is strange, I thought to do something like
GET profile => profile (0 means that we are on our profile)
GET profile/ =>profile (if there is a parameter, we pass it)
But I thought it was very crooked
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question