title: Rows not found, Codeiginiter Show Index
body: <p>I'm new with Codeigniter. I got error on my code using Codeigniter. My index doesn't show the row of my datatable, even my datatable had data in it. Anyone can find my error or typo text on my code? Please help me :(.
  btw I have 2 controllers.</p>
  <p>Here's my first controller (modules-&gt;api-&gt;controller-&gt;Tower.php)</p>
  <pre><code>defined('BASEPATH') OR exit('No direct script access allowed');
  
  require_once APPPATH . '/core/MY_Auth.php';
  require 'vendor/autoload.php';
  use PhpOffice\PhpSpreadsheet\Spreadsheet;
  use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  
  class Tower extends MY_Auth
  {
      protected $ruleMsg;
      function __construct()
      {
          parent::__construct();
          $this-&gt;load-&gt;model('Model_tower');
          $this-&gt;load-&gt;library('Pagingmeta');
          $this-&gt;load-&gt;library('Validate');
          $this-&gt;ruleMsg = '%s must be filled';
      }
  
      public function index_get($id = '') {
          if (!empty($id)) {
              return $this-&gt;get_detail($id);
          }
          $keyword = $this-&gt;get('search', true);
          $except = $this-&gt;get('excepth', true);
          $type = $this-&gt;get('type', true)??'list';
          $page = $this-&gt;get('page', true)??1;
          $limit = $this-&gt;get('limit', true)??10;
          $data = $this-&gt;Model_tower-&gt;get_list($keyword, $this-&gt;role, $this-&gt;regional, $page, $limit);
          $this-&gt;response([
              'message'       =&gt; 'Get tower success',
              'data'          =&gt; $data['data'],
              'meta'          =&gt; $this-&gt;pagingmeta-&gt;get_meta($data['total'], $limit, $page)
          ], REST_Controller::HTTP_OK);
      }
  
      private function get_detail($id) {
          $data = $this-&gt;Model_tower-&gt;get_detail($id);
          if (empty($data)) {
              return $this-&gt;response([
                  'message' =&gt; 'Data not found'
              ], REST_Controller::HTTP_BAD_REQUEST);
          }
  
          if ($this-&gt;regional != $data-&gt;regional &amp;&amp; $this-&gt;role != 'ADMN' &amp;&amp; $id != $this-&gt;userId) {
              return $this-&gt;response([
                  'message' =&gt; &quot;You didn't have right to access this data&quot;
              ], REST_Controller::HTTP_BAD_REQUEST);
          }
  
         if ($this-&gt;role == 'ADMN') {
              $data-&gt;is_editable = true;  
          }
  
          return $this-&gt;response([
              'message'       =&gt; 'Get tower success',
              'data'          =&gt; $data
          ], REST_Controller::HTTP_OK);
      }
  
      public function tower_post() {
          $this-&gt;validate_role();
          $rules = $this-&gt;rules_post($this-&gt;post(null, true));
          $params = $this-&gt;validate-&gt;validation($this-&gt;post(null, true), $rules);
          if (!$params['status']) {
              $this-&gt;response([
                  'message' =&gt; $params['errors'][0]
              ], REST_Controller::HTTP_BAD_REQUEST);
          }
          
          $params = $params['data'];
          if ($this-&gt;Model_tower-&gt;validate_site_id($params['site_id'])) {
              $this-&gt;response([
                  'message' =&gt; 'Site ID already exist'
              ], REST_Controller::HTTP_BAD_REQUEST);
          }
          $id = $this-&gt;Model_tower-&gt;tower_action($params, $this-&gt;userId);
          $this-&gt;response([
              'message'       =&gt; 'Create tower success',
              'data'          =&gt; $id
          ], REST_Controller::HTTP_CREATED);
      }
  
      public function tower_put($id = '') {
          $this-&gt;validate_role();
          $rules = $this-&gt;rules_post($this-&gt;put(null, true));
          $params = $this-&gt;validate-&gt;validation($this-&gt;put(null, true), $rules);
          if (!$params['status']) {
              $this-&gt;response([
                  'message' =&gt; $params['errors'][0]
              ], REST_Controller::HTTP_BAD_REQUEST);
          }
  
          $params = $params['data'];
          if ($this-&gt;Model_tower-&gt;validate_site_id($params['site_id'], $id)) {
              $this-&gt;response([
                  'message' =&gt; 'Site ID already exist'
              ], REST_Controller::HTTP_BAD_REQUEST);
          }
          $this-&gt;Model_tower-&gt;tower_action($params, $this-&gt;userId, $id);
          $this-&gt;response([
              'message'       =&gt; 'Update tower success',
              'data'          =&gt; $id
          ], REST_Controller::HTTP_OK);
      }
  
      public function upload_post() {
          $this-&gt;validate_role();
          $this-&gt;load-&gt;library('Uuid');
          $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($_FILES['data']['tmp_name']);
   
          $sheet = $spreadsheet-&gt;getActiveSheet();
          
          // Store data from the activeSheet to the varibale in the form of Array
          $data = array_values($sheet-&gt;toArray(null,true,true,true));
          
          $oldData = $this-&gt;Model_tower-&gt;get_all_data();
          $oldData = array_column($oldData, 'site_id');
          $insertData = [];
          $now = date('Y-m-d H:i:s');
          foreach($data as $index =&gt; $d) {
              if ($index == 0) {
                  continue;
              }
              $code = $this-&gt;uuid-&gt;generate();
              $type = '';
              $regional = '';
  
              $inputedType = $d['D'];
              if ($inputedType == 'MTEL') {
                  $type = 'mtel';   
              } else {
                  $type = 'reseller';
              }
  
              $inputedRegional = $d['G'];
              if ($inputedRegional == 'Jawa Timur') {
                  $regional = 'JATIM';   
              } else if ($inputedRegional == 'Jawa Tengah') {
                  $regional = 'JATENG';   
              } else {
                  $regional = 'BALNUS';
              }
  
              if (empty($d['A']) || empty($d['B']) || in_array($d['A'], $oldData)) {
                  break;
              }
  
              $insertData[] = [
                  'site_id'           =&gt; $d['A'],
                  'project_id'        =&gt; $d['B'],
                  'site_name'         =&gt; $d['C'],
                  'type'              =&gt; $type,
                  'company'           =&gt; $d['E'],
                  'address'           =&gt; $d['F'],
                  'regional_code'     =&gt; $regional,
                  'active_status'     =&gt; 1,
                  'created_at'        =&gt; $now,
                  'updated_at'        =&gt; $now,
                  'code'              =&gt; $code,
                  'created_by'        =&gt; $this-&gt;userId,
                  'updated_by'        =&gt; $this-&gt;userId
  
              ];
          }
  
          if (!empty($insertData)) {
              $this-&gt;Model_tower-&gt;insert_batch($insertData);
          }
  
          $this-&gt;response([
              'message'       =&gt; 'Bulk insert success',
          ], REST_Controller::HTTP_CREATED);
          
      }
  
      private function validate_role() {
          if ($this-&gt;role != 'ADMN') {
              return $this-&gt;response([
                  'message' =&gt; &quot;You didn't have right to access this action&quot;
              ], REST_Controller::HTTP_BAD_REQUEST);
          }
      }
  
      private function rules_post() {
          return  [
              [
                  'field' =&gt; 'site_id',
                  'label' =&gt; 'Site id',
                  'rules' =&gt; 'required',
                  'errors' =&gt; ['required' =&gt; $this-&gt;ruleMsg]
              ],
              [
                  'field' =&gt; 'project_id',
                  'label' =&gt; 'Project id',
                  'rules' =&gt; 'required',
                  'errors' =&gt; ['required' =&gt; $this-&gt;ruleMsg]
              ],
              [
                  'field' =&gt; 'name',
                  'label' =&gt; 'Name',
                  'rules' =&gt; 'required',
                  'errors' =&gt; ['required' =&gt; $this-&gt;ruleMsg]
              ],
              [
                  'field' =&gt; 'type',
                  'label' =&gt; 'Type',
                  'rules' =&gt; 'required',
                  'errors' =&gt; ['required' =&gt; $this-&gt;ruleMsg]
              ],
              [
                  'field' =&gt; 'regional',
                  'label' =&gt; 'Regional',
                  'rules' =&gt; 'required',
                  'errors' =&gt; ['required' =&gt; $this-&gt;ruleMsg]
              ],
              [
                  'field' =&gt; 'address',
                  'label' =&gt; 'Address',
                  'rules' =&gt; 'required',
                  'errors' =&gt; ['required' =&gt; $this-&gt;ruleMsg]
              ],
              [
                  'field' =&gt; 'company',
                  'label' =&gt; 'Company',
                  'rules' =&gt; 'required',
                  'errors' =&gt; ['required' =&gt; $this-&gt;ruleMsg]
              ],
              [
                  'field' =&gt; 'status',
                  'label' =&gt; 'Status',
                  'rules' =&gt; 'required',
                  'errors' =&gt; ['required' =&gt; $this-&gt;ruleMsg]
              ],
          ];
      }
  
  } 
  
  </code></pre>
  <p>and this is my second Controller (Controllers-&gt;Tower.php)</p>
  <pre><code>defined('BASEPATH') OR exit('No direct script access allowed');
  
  require_once APPPATH . '/core/MY_Cont.php';
  
  class Tower extends MY_Cont
  {
      public function __construct()
      {
          parent::__construct();
      }
  
      public function index() {
          $opts   = array(
              'content_only'      =&gt; false,
              'parent_menu'       =&gt; 'tower',
              'child_menu'        =&gt; 'List Tower',
              'nav_target'        =&gt; 'tower_list',
          );
          
          $this-&gt;view('tower/index', $opts);
      }
  
      public function detail($code = null) {
          if (empty($code)) {
              $this-&gt;render_invalid();
          }
  
          $fetch_detail   = $this-&gt;get_data_tower($code);
          
          if ($fetch_detail['code'] !== 200) {
              $this-&gt;render_invalid();
          }
          
          $opts           = array(
              'content_only'      =&gt; false,
              'parent_menu'       =&gt; 'tower',
              'child_menu'        =&gt; 'Tower Detail',
              'tower'             =&gt; $fetch_detail['response']-&gt;data,
              'nav_target'        =&gt; 'tower_list',
          );
          
          $this-&gt;view('tower/detail', $opts);
      }
  
      public function new() {
          $regional       = $this-&gt;get_regional();
  
          $opts           = array(
              'content_only'      =&gt; false,
              'parent_menu'       =&gt; 'tower',
              'child_menu'        =&gt; 'Add New Tower',
              'list_region'       =&gt; $regional['response']-&gt;data,
              'nav_target'        =&gt; 'tower_new',
          );
          
          $this-&gt;view('tower/new', $opts);
      }
  
      public function bulk() {
          $opts   = array(
              'content_only'      =&gt; false,
              'parent_menu'       =&gt; 'tower',
              'child_menu'        =&gt; 'Upload Tower',
              'nav_target'        =&gt; 'tower_bulk',
          );
          
          $this-&gt;view('tower/bulk', $opts);
      }
  
      public function edit($code = null) {
          if (empty($code)) {
              $this-&gt;render_invalid();
          }
  
          $fetch_detail   = $this-&gt;get_data_tower($code);
          
          if ($fetch_detail['code'] !== 200) {
              $this-&gt;render_invalid();
          }
  
          $regional       = $this-&gt;get_regional();
  
          $opts           = array(
              'content_only'      =&gt; false,
              'parent_menu'       =&gt; 'tower',
              'child_menu'        =&gt; 'Edit Tower Detail',
              'tower'             =&gt; $fetch_detail['response']-&gt;data,
              'list_region'       =&gt; $regional['response']-&gt;data,
              'nav_target'        =&gt; 'tower_list',
          );
          
          $this-&gt;view('tower/edit', $opts);
      }
  
      private function render_invalid() {
          header('HTTP/1.0 404');
          $opts   = array(
              'content_only'      =&gt; true,
              'cfg_mainclass'     =&gt; 'fullpage',
              'private_routing'   =&gt; false,
          );
  
          $this-&gt;view('layouts/404', $opts);
          exit();
      }
  
      private function get_data_tower($id = '') {
          if (empty($id)) {
              $curl       = curl_init(base_url() . 'api/tower');
          } else {
              $curl       = curl_init(base_url() . 'api/tower/' . $id);
          }
  
          curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($curl, CURLOPT_HTTPHEADER, array(
              'Authorization: ' . $this-&gt;session-&gt;userdata('usertoken'),
          ));
  
          $result     = json_decode(curl_exec($curl));
          $httpcode   = curl_getinfo($curl, CURLINFO_HTTP_CODE);
          curl_close($curl);
  
          return array(
              'code'      =&gt; $httpcode,
              'response'  =&gt; $result,
          );
      }
  
      private function get_regional() {
          $curl       = curl_init(base_url() . 'api/master/regional');
  
          curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($curl, CURLOPT_HTTPHEADER, array(
              'Authorization: ' . $this-&gt;session-&gt;userdata('usertoken'),
          ));
  
          $result     = json_decode(curl_exec($curl));
          $httpcode   = curl_getinfo($curl, CURLINFO_HTTP_CODE);
          curl_close($curl);
  
          $response   = array(
              'code'      =&gt; $httpcode,
              'response'  =&gt; $result,
          );
          
          return $response;
      }
  }
  </code></pre>
  <p>and this is my index.php</p>
  <pre><code>    &lt;div class=&quot;container-fluid&quot;&gt;
          &lt;div class=&quot;row&quot;&gt;
              &lt;div class=&quot;col-12&quot;&gt;
                  &lt;div class=&quot;mainpanel&quot;&gt;
                      &lt;div class=&quot;mainpanel-header&quot;&gt;
                          &lt;div class=&quot;row align-items-end&quot;&gt;
                              &lt;div class=&quot;col-9&quot;&gt;
                                  &lt;h3&gt;List Tower&lt;/h3&gt;
                                  &lt;h5&gt;Click on tower to view detail&lt;/h5&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;col text-right&quot;&gt;
                                  &lt;a href=&quot;{{ base_url }}tower/new&quot; class=&quot;panel-cta&quot;&gt;
                                      Add new tower
                                  &lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;form method=&quot;post&quot; action=&quot;&quot; id=&quot;form-filter-data&quot; autocomplete=&quot;off&quot;&gt;
                          &lt;div class=&quot;digi-tablefilter&quot;&gt;
                              &lt;div class=&quot;filter-inputholder&quot;&gt;
                                  &lt;label&gt;Search&lt;/label&gt;
                                  &lt;input type=&quot;text&quot; name=&quot;search&quot; placeholder=&quot;Search keyword&quot; id=&quot;filter-search&quot; /&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;filter-inputholder&quot;&gt;
                                  &lt;input type=&quot;submit&quot; value=&quot;Apply filter&quot; /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                      &lt;span class=&quot;table-information&quot; id=&quot;t-info&quot;&gt;&lt;/span&gt;
                      &lt;div class=&quot;digi-tableholder&quot;&gt;
                          &lt;table&gt;
                              &lt;thead&gt;
                                  &lt;tr&gt;
                                      &lt;th&gt;Name&lt;/th&gt;
                                      &lt;th&gt;Project ID&lt;/th&gt;
                                      &lt;th&gt;Site ID&lt;/th&gt;
                                      &lt;th&gt;Regional&lt;/th&gt;
                                      &lt;th&gt;Company&lt;/th&gt;
                                  &lt;/tr&gt;
                              &lt;/thead&gt;
                              &lt;tbody id=&quot;tower-table-value&quot;&gt;&lt;/tbody&gt;
                          &lt;/table&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;row&quot;&gt;
              &lt;div class=&quot;col&quot;&gt;
                  &lt;div id=&quot;test-pag&quot;&gt;&lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/section&gt;
  &lt;script&gt;
       $(document).ready(function() {
          const payload = {
              page: 1,
              limit: 10,
              search: '',
          }
  
          fetchListData(payload);
      });
  
  
      function fetchListData(payload) {
          var apiURL = &quot;{{ api_server ~ 'tower' }}&quot;;
          var userToken = getUserToken();
  
          $.ajax({
              url: apiURL,
              type: &quot;GET&quot;,
              data: payload,
              headers: {
                  Authorization: userToken,
              },
              success: function(response) {
                  const { data, message, meta } = response;
                  buildDataTable(data, meta);
              },
              error: function(response) {
                  const { responseJSON } = response;
                  addNotification({
                      type: 'error',
                      title: 'Fetching data tower gagal',
                      message: responseJSON.message,
                  });
                  return;
              }
          });
      }
  
      function buildDataTable(data, metadata) {
          const target = document.getElementById(&quot;tower-table-value&quot;);
          const txtResult = document.getElementById(&quot;t-info&quot;);
          $(&quot;#tower-table-value&quot;).empty();
          target.innerHTML = &quot;&quot;;
          txtResult.innerHTML = &quot;&quot;;
  
          if (data.length == 0) {
              buildEmptyRows();
              return;
          }
  
  
          $.each(data, function(idx, item) {
              const { id, name, project_id, site_id, regional, company } = item;
  
              const tr = document.createElement('tr');
  
              const nameHolder = document.createElement('td');
              const projectHolder = document.createElement('td');
              const siteHolder = document.createElement('td');
              const regionalHolder = document.createElement('td');
              const companyHolder = document.createElement('td');
  
  
              nameHolder.innerHTML = name;
              projectHolder.innerHTML = project_id;
              siteHolder.innerHTML = site_id;
              regionalHolder.innerHTML = regional;
              companyHolder.innerHTML = company;
  
  
              tr.appendChild(nameHolder);
              tr.appendChild(projectHolder);
              tr.appendChild(siteHolder);
              tr.appendChild(regionalHolder);
              tr.appendChild(companyHolder);
  
              tr.onclick = function(e) {
                  window.location.href = `{{ base_url }}tower/detail/${item.id}`;
              }
  
              target.appendChild(tr);
          });
  
          var $resultText = `Showing result with keyword &lt;strong&gt;${$(&quot;#filter-search&quot;).val() == '' ? '-' : $(&quot;#filter-search&quot;).val()}&lt;/strong&gt; ${metadata.total} row(s) found.`;
          txtResult.innerHTML = $resultText;
  
          if (metadata.last_page &gt; 1) {
              buildPagination(metadata);
          } else {
              hideLoader();
          }
      }
  
      function buildEmptyRows() {
          const target = document.getElementById(&quot;tower-table-value&quot;);
          const txtResult = document.getElementById(&quot;t-info&quot;);
  
  
          var $resultText = `Showing result with keyword &lt;strong&gt;${$(&quot;#filter-search&quot;).val() == '' ? '-' : $(&quot;#filter-search&quot;).val()}&lt;/strong&gt; • 0 row(s) found.`;
          txtResult.innerHTML = $resultText;
  
          const tr = document.createElement('tr');
          const td = document.createElement('td');
          td.colspan = 5;
          td.innerHTML = 'No Rows Found.';
  
          tr.appendChild(td);
          target.appendChild(tr);
          
          hideLoader();
      }   
  
      function buildPagination(metadata) {
          const { from, to, last_page, current_page, per_page, total } = metadata;
          $(&quot;#test-pag&quot;).pagination({
              items: total,
              itemsOnPage: per_page,
              currentPage: current_page,
              onPageClick: function(pageNumber, event) {
                  event.preventDefault();
                  const payload = {
                      page: pageNumber,
                      limit: per_page,
                      search: '',
                  }
  
                  fetchListData(payload);
              }
          });
      }
  
      $(&quot;#form-filter-data&quot;).submit(function(e) {
          e.preventDefault();
          const $payload = {
              page: 1,
              limit: 10,
              search: $(&quot;#filter-search&quot;).val()
          }
  
          fetchListData($payload);
      })
  &lt;/script&gt;
  </code></pre>
  <p>I'll very thankful if u can solve my problem :D</p>