I have created my first Yii site using the tutorials and information here. It has a user system (using the userGroups extension) and an article system I created using the blog tutorial, if it helps the site is at ns2hub.com!
I display the username with each article on the main page, articles page and on the specific view. I can easily display the user info on the article view, as I already have the id of the article in the controller. I cannot manage to get the user info on the other pages that display more than one article though.
I do not currently understand how to get Yii to automatically attach the user info when I call the articles. I think I need to get the model relations right, is there anything else?
I will post my tables simplified and then my model relationship code.
I would also appreciate links to any resources that could help me to understand how this works. The categories and comments are working fine using the code automatically generated by Yii (Gii), I would love to understand how it works well enough to feel comfortable adding more into my app.
I have tried many different combinations of relationships and tried to use the guides around to get it right. Do I need to do something else too? Am I missing something? Any advice or help is appreciated!
I have tried using var_dump to check what information I have. I successfuly get the Articles, along with their corresponding categories and comments, but no user data. It is infuriating and I must be missing something.
Thanks for replying mentel, I think I was not clear enough.
If I can get access to the info, I can easily output it on the page. The authors info is simply not in $data, which is the problem. For whatever reason I cannot get Yii to collect the author info along with the article, category and comments.
I would really appreciate any help, I am pulling my hair out and going grey far too young!
You can try adding a with parameter to your criteria.
Also, please check whether the field tbl_article.author_id for the row selected isn’t null and, if you don’t have a constraint set, whether it indeed exists in tbl_usergroups_user.
Thank you so much Rodrigo you have saved me, this works flawlessly. Thank you for showing me this, I will find it really useful in the future and you have saved me from going grey too early!