03.12
php
saved
jelmer
Note
This is some code for adding ajax comments to a post (similar to blog tutorial) using cakephp 1.2, Right now it's not working yet so help is welcome.
This is some code for adding ajax comments to a post (similar to blog tutorial) using cakephp 1.2, Right now it's not working yet so help is welcome.
- //comments_controller.php, function add()
- function add()
- {
- if($this->RequestHandler->isAjax())
- {
- $this->Comment->create();
- if ($this->Comment->save($this->data))
- {
- $this->Comment->recursive =-1;
- $comments = $this->Comment->findAllByPostId($this->data['Comment']['post_id']);
- $this->viewPath = 'elements'.DS.'posts';
- $this->render('comments');
- }
- }
- }
- //part of views/posts/view.ctp
- <a name="view-comments" id="view-comments"></a>
- <div class="comments" id="PostComments">
- <? foreach ($post['Comment'] as $row=>$comment): ?>
- <? //if($comment['visible'] == 1){ ?>
- <div class="comment_<? echo $alternate->alternate($row,"1","2") ?>">
- </div>
- <? /*}*/ endforeach; ?>
- </div>
- <h2>What do you think?</h2>
- <!-- ajax submit form -->
- <?php
- ?>
- <!-- end ajax submit form -->
- <? debug($comments) ?>
- // views/elements/posts/comments.ctp:
- <h2>Comments (<? //echo sizeof($post['Comment']) ?>)</h2><!-- this is views/elements/posts/comment.ctp -->
- <? foreach ($comments as $row=>$comment): ?>
- <? //if($comment['visible'] == 1){ ?>
- <div class="comment_<? echo $alternate->alternate($row,"1","2") ?>">
- </div>
- <? endforeach; ?>
- <? } ?>
Parsed in 0.239 seconds, using GeSHi 1.0.7.14