Ben sadece benim ilk CI uygulaması başladı. Bazı mesajları görüntüleyen bir görünümü var. Her yazılan birden fazla yorum olabilir ve sonraki her yazılan yorumların sayısını göstermek istiyorum.
Şimdiye kadar tüm db çağrı (bu değişen olacaktır) benim denetleyicisi vardır.
function index(){
$data['query'] = $this->db->get('posts');
$this->load->view('blog_view', $data);
}
Benim görüşüme göre:
<?php foreach($query->result() as $row):
<div class="post-box">
<p><?php echo $row->body; ?><small> added by <?php echo $row->username; ?> on <?php echo date ('d/m/Y',strtotime($row->created)); ?> <a href="<?php echo base_url(); ?>blog/comments/<?php echo $row->id; ?>"><img src="<?php echo base_url(); ?>images/comments_icon.png" /> 0</a></small></p>
</div>
<?php endforeach; ?>
Ben comment.post_id geçerli kaydın id = yorumların sayısını almak istiyorum. ve sonraki yorumlar simgesine görüntüler.
Bu herhangi bir yardım en takdir,
Cop
GÜNCELLEME
Denetleyici:
function index(){
//load the model
$this->load->model('City_model');
//call the model method
$data->posts = $this->City_model->get_posts();
$this->load->view('blog_view', $data);
}
Model (city_model.php):
<?php
class City_model extends Model{
function get_posts($id = NULL) {
//define optional id for single post
//if an id was supplied
if ( $id != NULL ) {
$this->db->where('id',$id);
}
// execute query
$query = $this->db->get('posts');
//make sure results exist
if($query->num_rows() > 0) {
$posts = $query->result();
} else {
return FALSE;
}
//create array for appended (with comments) posts
$appended_posts_array = array();
//loop through each post
foreach ($posts as $post) {
//get comments associated with the post
$this->db->where('post_id', $post->id)
$comments = $this->db->get('comments');
//if there are comments, add the comments to the post object
if($comments->num_rows() > 0) {
$post->comments = $comments;
}
else {
$post->comments = array();
}
//rebuild the returned posts with their comments
$appended_posts_array[] = $post;
}
//if post id supplied, only return the single post object
if ($id != NULL) {
return $appended_registration_array[0];
}
else {
return $appended_registration_array;
}
}
}