title: Sorting in CodeIgniter Pagination
body: <p>The other day I managed to implement Pagination in CI using a wonderful tutorial found on the net. The next day, I noticed that Sorting was not covered in the tutorial.
  So I went on to implement sorting, and successfully implemented it. However, the issue arose that the pagination links did not contain the specific URI Segments related to "sortfield" and "sortorder" and hence the confusion.</p>
  
  <p>If anyone knows about a way to implement sorting such that it is retained on all pages, let me know.</p>
  
  <p>My test URL :
  <a href="http://zzz.zzz.z.zz/frog/index.php/questions/page/1/id/desc" rel="nofollow">http://zzz.zzz.z.zz/frog/index.php/questions/page/1/id/desc</a>
  which is not retained when I click on page 2</p>
  
  <p>My code:</p>
  
  <pre><code>function page($offset = 0,$sortfield=null,$order=null) {
  /**
  * Removed all the unnecessary code
  */
      $config = array (
                      'base_url' =&gt; base_url () . 'index.php/questions/page/',
                      'total_rows' =&gt; $this-&gt;db-&gt;count_all ( 'questions' ),
                      'per_page' =&gt; $this-&gt;input-&gt;get ( 'perpage' ) ? $this-&gt;input-&gt;get ( 'perpage' ) : (@$layoutspecificpagination-&gt;per_page ? $layoutspecificpagination-&gt;per_page : 5),
                      'num_links' =&gt; 5,
                      'reuse_query_string' =&gt; true
              );
  
      $config ['total_rows'] = $this-&gt;questionsm-&gt;read ( $config ['per_page'], $offset, true );
  
      $this-&gt;pagination-&gt;initialize ( $config );
  }
  </code></pre>
  
  <p>Then in the view:</p>
  
  <pre><code>&lt;?php echo $this-&gt;pagination-&gt;create_links(); ?&gt;
  </code></pre>