Okay so, I'm working with CodeIgniter. posts.php is my view that displays all the posts, each post must display its corresponding comments, which is what I'm trying to achieve.
I have a method in my model that takes the postid($postid) and return its corresponding comment($comment), unless I call the model method via a controller method,how do I accompolish this?
This is my view :
<body>
<?php foreach ($post as $key):?>
<div class="container">
<div class="span10">
<div id="box" class="alert-message block-message info">
<div id="post" class="post">
<?php echo $key->content;?><br />
</div>
<div>
<p><?php //echo $comment;?></p> <!--HERE THE COMMENTS OF THE CORRESPONDNING POST MUST BE ECHOED-->
</div>
<div>
<a href="#" id="commentnow<?php echo $key->postid;?>"><p><em>Comment</em></p></a>
</div>
<div id="commentarea<?php echo $key->postid;?>">
<?php $name=array('name'=>"form$key->postid");
echo form_open("/welcome/comments/$key->postid",$name);
$data=array(
'id' => 'input',
'name'=> 'content',
'rows' => '2',
'placeholder' => "Write a comment...",
'autofocus' => 'TRUE'
);
echo form_textarea($data);
?>
<a href="JAVASCRIPT:form<?=$key->postid;?>.submit()" id="cbtn" class="btn primary small">Comment</a>
<?=form_close();?>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(function(){
$("div#commentarea<?=$key->postid;?>").hide();
$('a#commentnow<?=$key->postid;?>').click(function(){
$("div#commentarea<?=$key->postid;?>").slideToggle(250);
});
});
</script>
<?php endforeach;?>
</body>
This is my controller method that returns the comments that corresponds to the postid:
public function comments($postid)
{
//Post Comment
$comment=$this->input->post('content');
$data=array('content'=>$comment,'comment_postid'=>$postid);
$this->comments->postcomment($data);
//Retrieve
$comments['comment']=$this->comments->retrieve($postid);
$this->load->view('posts',$comments);
}
I'm a newbie,pardon me if my code is bad. I'm always looking forward to improving my code> Thanks for being patient. :)