Suggestions :) 1) If the user is viewing a post and wish to comment the post, then use a form in the post view and let the post controller ensure that the new comment is added to the post.
2) If the user is viewing all the comments to a post, then use a form in the comment view and let the comment controller ensure that the new comment is added to the post. In either case, you have to ensure that you know and provides the post id to use when saving the new comment. How you are doing that is up to you, but there are several ways: 1) Use the session to track the currently viewed post id. 2) Use a hidden input field in the comment post. 3) A combination of both, so as to ensure that the post ids are the same! Enjoy, John On Jun 25, 4:25 pm, GravyFace <[email protected]> wrote: > Been a while since I've done some cake (and last app was a > time-crunched blur) so thought I'd start fresh, from the beginning, > with a more relaxed deadline and get some fundamentals down correctly. > > Using the blog example, our models look like this: > > Post hasMany Comment > Comment belongsTo Post > > Let's say I want to add a new comment -- in the "add" view of > Comments.add action, I can create a hidden form field with the Post > Id; when I call save, the foreign key (post_id) is set for the Comment > and then saved accordingly, preserving the relationship between Post > and Comment. > > Because I want to keep the relationship in context to the user -- I > don't want them to go from /posts/view/1 to /comments/add, only to > have them choose a Post they want to comment on from a select field -- > it seems like I have two options: > > 1) include the comment form on the post view, using an element perhaps. > 2) pass the Post Id as an argument to the Comment.add action; save and > redirect back to posts/view/1. > > #1 is fine for a blog, but not for a User's Profile, which could be > too long to include in the User view. > #2 works I guess, but adding Post-specific view and redirect logic to > the CommentsController actions doesn't seem right, when (I think) I > should be trying to maintain a 1:1 relationship between controllers > and models. > > Any thoughts? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
