Cakephp: maintaining hasMany/belongsTo relationships in controller actions -


Forgive the title of the question; Spend 20 minutes to write something relevant (suspected if successful).

Anyway, using a blog as an example, our models look like this:

Many comment comments in the post areTo Post

Suppose I want to add a new comment: When saving the comment, before saving, I need to include the foreign key in the parent post (post.id) in the data array.

Because I want to make reference to the user in relation - I do not want them to choose a comment from a select area - here are two options: see I:

1) Enter the comment form in the post view.

2) Post ID as an argument (through GIT) in the comment. Action Action (or to write / write / write from session); Save and post back to parents. Observation.

Option 1 is great for a blog, but not for the user's profile, the form that can be neatly included in the user view can be very long. / P>

Option 2 works, I think, but I have to write some post-specific display / conditions on some comments. Action action, and it does not look right; Have I read, I should try to maintain 1: 1 relationships between controllers and models.

Is # 2 web mvc acceptable as best practice? Or is there another option that I see?

I have often seen together this post for posting (possibly using an element , If you want to do it somewhere else), but it was submitted to add the comment of the controller (in this case, in this case) and it had passed the ID of the post just a note - if you applied to private posts, etc. Additionally, the comments in the Controller's Ad Action checkup It would be best to do this.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -