开发者

Model View Referencing Another Model View

开发者 https://www.devze.com 2023-01-15 00:43 出处:网络
I have an Article model and I also have a Comment model. My article show page is rendering a view from the Comment view开发者_Go百科s. It is rendering a new comment form and a show comment form. If I

I have an Article model and I also have a Comment model. My article show page is rendering a view from the Comment view开发者_Go百科s. It is rendering a new comment form and a show comment form. If I reference a variable in the comment form, like @comment, does it look for the @comment in the article controller or does it look for it in the comment controller?


The views are independent from the controllers. Only one controller will be accessed based on your routing settings, regardless if you include code from another view.

However, it sounds like you're doing things the "wrong" way. Article-Comment is a classic example of a nested resource and is probably what you're looking for. Try this article.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号