Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeigniter pagination on function index
    primarykey
    data
    text
    <p>I edited this after figuring out a few things but is this a good way if I want my links on index? Without the function page, it will not work correctly if the base_url is test/index, but test/test will work.</p> <p>controller</p> <p>class Test extends CI_Controller {</p> <pre><code>public function __construct() { parent::__construct(); $this-&gt;load-&gt;model('Test_model'); $this-&gt;load-&gt;library('pagination'); } public function index() { $page['title'] = ''; $page['file'] = 'test/index'; $config['base_url'] = base_url().'test/page'; $config['total_rows'] = $this-&gt;Test_model-&gt;record_count(); $config['per_page'] = 2; $config['num_links'] = 5; $offset = $this-&gt;uri-&gt;segment(3,0); $this-&gt;pagination-&gt;initialize($config); $page['data']['items'] = $this-&gt;Test_model-&gt;getItems($config['per_page'], $offset); $page['data']['pagination'] = $this-&gt;pagination-&gt;create_links(); $this-&gt;load-&gt;view('template', $page); } public function page() { $page['title'] = ''; $page['file'] = 'test/index'; $config['base_url'] = base_url().'test/page'; $config['total_rows'] = $this-&gt;Test_model-&gt;record_count(); $config['per_page'] = 2; $config['num_links'] = 5; $offset = $this-&gt;uri-&gt;segment(3,0); $this-&gt;pagination-&gt;initialize($config); $page['data']['items'] = $this-&gt;Test_model-&gt;getItems($config['per_page'], $offset); $page['data']['pagination'] = $this-&gt;pagination-&gt;create_links(); $this-&gt;load-&gt;view('template', $page); } </code></pre> <p>}</p> <p>model</p> <pre><code>public function record_count() { return $this-&gt;db-&gt;count_all('item'); } public function getItems($limit, $offset) { $query = $this-&gt;db-&gt;get('item', $limit, $offset); $result = $query-&gt;result(); return $result; } </code></pre> <p>view</p> <pre><code>&lt;h2&gt;&lt;?=$pagination; ?&gt;&lt;/h2&gt; &lt;table&gt; &lt;?php foreach($items as $item) { ?&gt; &lt;tr&gt;&lt;td&gt;&lt;?=$item-&gt;name?&gt;&lt;/td&gt;&lt;/tr&gt; &lt;?php } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload