So I'm trying to extend the Blog tutorial adding some comments:

Post hasMany Comments

I want to display the add comment form in the same view as the 'post
view'. Thing is I don't know the best way to get this approach. I
thought about three ways:

Creating a function in Comments Controller to handle the data.
Creating a function in Post Controller to handle the data.
Deal with the data in the same function that deals with the post
views.
The main problem with the two first 'solutions' is that the validation
errors doesn't show up in the form unless I do some messy hacking of
saving the invalidated field in a session variable and then parsing
the variable on the beforeFilter callback, like this:

function beforeFilter () {
    if ($this->Session->check('comment_error')) {
        $this->Post->Comment->validationErrors = $this->Session-
>read('comment_error');
        $this->Session->delete('comment_error');
    }
}

What I basically do is adapt the invalidated fields to the actual view
and allow it to show properly. This works really well, but it seems so
ugly to me. What would be the best approach?

Another related question: should a controller reflect a view? I mean
on that example, I thought about only having a Comment Model and
dealing with all the data in the controller where's the form to add a
comment (even though it's in the Post Controller).

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to