Welcome Guest, Not a member yet? Register   Sign In
Help CI Pagination not determining URI Segment
#1

[eluser]micha8l[/eluser]
I'm having trouble getting pagination to work. In the manual it says, "The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it."

Okay, so I omit this preference, and then it does not determine the page number... so anyone know how it automatically determines the page number... is it by placement e.g., does the pagination segment need to be at the end or the URL like http://example.com/controller/action/page/1 or is it by the name given to the segment?

Here's my code:
Model
Code:
public function paginate_comments($base_url, $article_id, $per_page, $pending = 'no')
    {
$this->pagination->initialize(array(
     'base_url' => $base_url,
     'total_rows' => $this->db->get_where('crubs_articles_comments', array('article_id' => $article_id, 'comment_pending' => $pending))->num_rows(),
     'per_page' => $per_page,
     'num_links' => 5,
     'cur_tag_open' => ' <strong>&lt; ',
     'cur_tag_close' => ' &gt;</strong>',
));
$links = $this->pagination->create_links();
return ( ! empty($links))? $links : 0;
    }

View
Code:
&lt;?php if(isset($comment_pagination) AND $comment_pagination): echo $comment_pagination; endif; ?&gt;

Controller
Code:
public function pending()
    {
$this->_is_logged_in('view pending comments.', 'articles/login', current_url());
$this->_is_author_registered('view pending comments.', 'authors/register', current_url());
$this->load->model(array('articles_categories_model', 'articles_model', 'articles_comments_model'));
$this->load->library('partial');
$this->_set_ids('no', TRUE, 3, 4);
$actions = $this->uri->uri_to_assoc(5, array('approve', 'disapprove', 'page', 'order'));
$offset = ($actions['page'])? (int) $actions['page'] : 0;
$current_url = base_url('articles/pending') . '/' . $this->uri->segment(3) . '/' . $this->uri->segment(4);
$order_url = $current_url;
$pagination_url = $current_url;

if($actions['approve'])
{
     $this->articles_comments_model->update_comment($actions['approve']);
}
else if($actions['disapprove'])
{
     $this->articles_comments_model->delete_comment($actions['disapprove']);
}

if($actions['page'])
{
     $order_url .= '/page/' . $offset;
}

switch ($actions['order']) {
     case 'author':
  $actions['order'] = 'crubs_authors.author_username';
  $pagination_url .= '/order/author';
  break;

     case 'comment':
  $actions['order'] = 'crubs_articles_comments.comment_date_created';
  $pagination_url .= '/order/comment';
  break;

     case 'article':
  $actions['order'] = 'crubs_articles.article_title';
  $pagination_url .= '/order/article';
  break;

     default:
  $actions['order'] = 'crubs_articles_comments.comment_date_created';
  break;
}

$this->partial->replace(array(
     'centre' => array(
  'articles/pending' => array(
      'pending_comments' => $this->articles_comments_model->read_pending_comments(ART_ID, $actions['order'], $offset),
      'comment_pagination' => $this->articles_comments_model->paginate_comments($pagination_url . '/page/', ART_ID, 4, 'yes'),
      'order_url' => $order_url,
  ),
     ),
));

return $this->layout_one_column();
    }


Messages In This Thread
Help CI Pagination not determining URI Segment - by El Forum - 04-09-2012, 01:06 PM
Help CI Pagination not determining URI Segment - by El Forum - 04-09-2012, 03:15 PM
Help CI Pagination not determining URI Segment - by El Forum - 04-09-2012, 03:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB