2011-12-11 69 views
1

我正在嘗試將一篇長篇文章分頁,以便在基於codeigniter框架構建的網站的移動設備上查看。 我已經能夠確定文章的頁數,但是在創建鏈接和能夠將參數傳遞給uri進行分頁時丟失了。 這是我的代碼從我的控制器分頁的長文章

function view_post($alias) 
     { 
      $post = $this->post_model->load_post($alias); 
      $data['title'] = $post->post_title; 
      $data['logged'] = $this->ion_auth->logged; 
      $data['user_id'] = $this->ion_auth->user; 
      $data['username'] = $this->ion_auth->username; 
      $data['comments'] = $this->comment_model->count_post_comments($post->ID); 
      $link = strtolower($post->name)."/".$post->alias; 
      $data['post_link'] = "www.giggsmagazine.com/".$link; 
      $data['post'] = $post; 

      // Article Pagination for long articles 
      $posts = explode("<!-- pagebreak -->",$post->post_content); 
      $page_count = count($posts) - 1; 
      $data['pages'] = $page_count; 
      $data['posts'] = $posts; 
      if($this->isMobile()) 
      { 
       $device = $this->agent->mobile; 
       switch($device) 
       { 
        case "BlackBerry": 
        $this->load->view('mobile/bb/inc/bb_header',$data); 
        $this->load->view('mobile/bb/posts/view_post'); 
        $this->load->view('mobile/bb/inc/bb_footer'); 
        break; 
        case "Apple Iphone" || "Apple Ipod Touch": 
        $this->load->view('mobile/iphone/inc/iphone_header',$data); 
        $this->load->view('mobile/iphone/posts/view_post'); 
        $this->load->view('mobile/iphone/inc/iphone_footer'); 
        break; 
        default: 
        $this->load->view('mobile/generic/inc/generic_header',$data); 
        $this->load->view('mobile/generic/view_post'); 
        $this->load->view('mobile/generic/inc/generic_footer'); 
        break; 
       } 
      }else { 
      $this->load->view('templates/site_header',$data); 
      $this->load->view('posts/view_post'); 
      $this->load->view('templates/site_footer'); 
      } 
     } 

請點我在正確的方向

回答

0

你嘗試過這麼遠嗎?你可能會更好地使用javascript/jQuery爲客戶端分頁(只是一個簡單的'閱讀更多'鏈接會將數據限制到某個字符數限制),但如果你想使用代碼在服務器端進行操作「VE已經寫好,你可能會做這樣的事情:

添加一個新的‘頁面’參數view_post:

function view_post($alias, $page = 0) 

爲您的文章內容創建一個新變量

$data['post_content'] = $posts[$page]; 

要顯示分頁,請在您的視圖中輸入如下內容:

for ($i = 0; $i <= $page_count; $i++) { 
    echo "<a href='/path/to/view_post/{$alias}/{$i}'>{$i}</a>"; 
} 

這應該讓你走上正軌。