2013-08-21 163 views
0

我認爲,從數據庫中獲取所有數據,我不會在我的代碼中進行分頁。在codeigniter分頁不工作

我會嘗試這種方式在我的網站上進行分頁,但不顯示分頁。

的觀點是這樣的: -

<ol class="timeline2 clear"> 
    <li class="spine"> 

    </li> 

    <?php 
    $counter=0; 
    //print_r($response); 
    foreach ($response as $row) { 
    if($counter % 2 == 0){$class= "left";} else $class="right"; 
    ?> 

    <li class="<?=$class ?>"> 
    <i class="pointer"></i> 
    <div class="unit"> 

     <!-- Story --> 
     <div class="storyUnit"> 
     <div class="imageUnit"> 
     <? if (empty($row->pic)) { ?> 
      <a href="#"><img width="32" height="32" alt="" src="images/nopic.png"></a> 
      <? } else { ?> 
      <a href="#"><img width="32" height="32" alt="" src="uploads/<?php echo $row->pic; ?>"></a> 
      <div id="delpost" style="float:left"> 
      <a href="./myaccount/deletePostInProfile/<?=$row->ev_id;?>" id="deletepost">X</a> 
      </div> 
      <? } ?> 
      <div class="imageUnit-content"> 
      <h4><a href="./myaccount/profile/<?php echo $row->id; ?>"><?php echo $row->fullname; ?></a></h4> 
      <p><?php echo $row->ev_date ?></p> 
      </div> 

     </div> 

     <p> <?php echo $row->ev_text; ?><br /> 
     <? if (!empty($row->ev_pic)) { ?> 
     <img src="uploads/<?php echo $row->ev_pic ?>" width="250" height="250"</p> 
     <? } ?></p> 

     </div> 
     <!--/Story --> 

     <!-- Units --> 
     <ol class="storyActions" id="storyActions<?php echo $row->ev_id; ?>"> 
<? 
$selectComment = mysql_query("select * from comment,users where 
comment.co_postid = '".$row->ev_id."' 
and comment.co_userid = users.id order by co_date DESC "); 
while($rows=mysql_fetch_array($selectComment)){ 
?> 
     <div id="resultcomment<?php echo $row->ev_id; ?>"></div> 
     <div id="resultcomment" style="border-top:1px solid #fff;"> 
     <a href="./myaccount/profile/<?php echo $rows['id']; ?>"> 
     <img src="uploads/<?=$rows["pic"];?>" width="32" height="32" class="rightc" /> 
     </a> 
     <b><a href="./myaccount/profile/<?php echo $rows['id']; ?>"><?=$rows["fullname"]; ?></a></b> 
     <span>&nbsp;&nbsp;</span> 
     <span><?=$rows["co_comment"]; ?></span> 
     <br /> 
     <span class="commentdate"><?=$rows["co_date"]; ?></span></br></div> 
<? } ?>  

     <form action="" method="post" accept-charset="utf-8"> 
     <input type="text" class="commentprofile" id="comment<?php echo $row->ev_id; ?>" name="comment<?php echo $row->ev_id; ?>" size="41" /> 
     <input type="hidden" id="postid<?php echo $row->ev_id; ?>" name="postid<?php echo $row->ev_id; ?>" size="41" value="<?php echo $row->ev_id; ?>" /> 
     <button type="button" id="submit" onclick="add_comment(<?php echo $row->ev_id; ?>)">ارسل</button> 
     </form> 

     </ol> 
     <!--/Units --> 

    </div> 
    </li> 

    <?php $counter++; } ?> 
    <div class="clear"></div> 
</ol> 

<? } ?> 

    <div> 

     <?php echo $this->pagination->create_links(); ?> 

    </div> 

和我的控制器: -

public function profile($user_id) { 

     $check = new User(); 
     $ex = $check->where('id',$user_id)->count(); 
     if($ex == 0){ redirect('./home'); } 
     else { 
     $user = new User($user_id); 


/************************************** Post *******************************************************************/ 
     $this->load->model('blog'); 

     if(isset($_POST['post'])){ 
     // Config setup 
     $config['base_url'] = base_url().'/myaccount/profile/'.$user_id.'/'; 
     $config['total_rows'] = 20; 
     $config['per_page'] = 10; 
     $config['num_links'] = 5; 
     // Initialize 
     $this->pagination->initialize($config); 

     if(strlen($_FILES['inputUpProfile']['name']) > 0) 
     { 
     $pic = $this->do_upload('inputUpProfile'); 

     if ($this->input->post('post') == ''){$type="image";} else {$type="image-with-text";} 
     } 

     else {$pic = ""; $type = "text"; } 

      $result = $this->blog->addPost($_SESSION['user_id'], $type , $this->input->post('post'),$pic); 
     } 
     if(isset($_SESSION['user_id']) || !empty($_SESSION['user_id'])){ 
     $result = $this->blog->getPost($user_id, 0 , 10); 
     $this->template->build("profile" , array("response"=>$result));  
     } 
     else{ 
     $this->template->build('registration_view',$this->data); 
     } 


     $this->data['user'] = $user; 
     $this->data['errors'] = $this->errors; 
     $this->template->set_layout('myaccount'); 
     $this->template->build('profile',$this->data); 


     } 
    } 

模塊: -

function getPost($user_id, $from, $to) { 
     $query = $this->db->query("SELECT * FROM events,users 
     where events.ev_user_id = '".$user_id."' 
     and events.ev_user_id = users.id 
     order by events.ev_date DESC limit 10"); 



    return $query->result(); 

} 

爲什麼不分頁在我的網站上顯示?

回答

0

在控制器後您初始化分頁:

$this->data['pagination_links'] = $this->pagination->create_links(); 

然後在你想要的分頁鏈接出現的觀點:

echo $pagination_links; 

您正在試圖呼應他們在您的視圖,而不首先在控制器中創建它們。文檔中的示例很糟糕,因爲它只是顯示您在控制器本身中將它們回顯出來。