Hi eDevil,

If you define the model associations (Blog has many comments, comments
belong to Blogs) cake will do all the work for you.

Compare your code with the following:

// In your comment controller

    function add()
    {
        if (empty($this->params['data']))
        {
            $this->Session->setFlash ("No direct access ;o)");
        }
        else
        {
            if ($this->Comment->save($this->params['data']))
            {
                $this->Session->setFlash ("Comment added");
            }
            else
            {
                $this->Session->setFlash ("Error adding comment");
            }
        }
        $Url = $this->referer("/");
        $this->redirect ($Url);
    }

// In your blog view after displaying the blog itself.
<?php
if (isset($data['Comment']))
{
    foreach ($data['Comment'] as $Comment)
    {
    echo "<div class=\"commentbody\">";
    echo $Comment['body'];
    echo "</div>";
    echo "<div class=\"commenttitle\">";
    echo "written by ".$Comment['Name']."
".$time->timeAgoInWords($Comment['created']);
    echo "</div>";
    }
}
else
{
    echo "No comments yet.";
}
?>
</div>
<div id="addcomment">
echo $html->formTag("/Comments/add");
echo
$html->hidden("Comment/blog_id",(Array('value'=>$data['Blog']['id'])));
echo $html->textarea("Comment/body", Array("cols"=>60,"rows"=>5));
echo "<br>";
echo $html->submit("Add Comment");
?>
</form>
</div>

//In your blog controller you don't need to complicate things
    function view($id)
    {
        $this->Blog->setId($id);
        $this->set('data', $this->{Blog->read());
    }

The above is a simplified version of what I put in place on my own
personal site - it may contain minor syntax errors as I edited it just
now before sending ;).

Hope this helps you solve your own problem (Note the hidden field for
Blog_id), and as ever comments welcome

Cheers,

AD7six


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to