title: CodeIgniter 4: Pass $data to the View file
body: <p>Can someone help me with this? I can't figure out on how can I show the results on the View file. I tried using <code>$this-&gt;load-&gt;view('list-logs',$data);</code> but it shows the error <code>Call to a member function view() on null</code>.</p>
  <p>CONTROLLER</p>
  <pre><code>public function getLogs()
      {
          helper(['form']);
  
          $EstMod = new EstMod();
          $data['est_data'] = $EstMod-&gt;orderBy('e_id', 'DESC')-&gt;findAll();
  
          $rep_est = $this-&gt;request-&gt;getPost('rep_est');
          $rep_date = $this-&gt;request-&gt;getPost('rep_date');
  
          $builder = $this-&gt;db-&gt;table(&quot;logs as l&quot;);
              $builder-&gt;select('l.l_id, u.fname, u.mname, u.lname, u.dept, u.user_type, u.u_grdsec, e.e_name, l.date_added, DATE(l.date_added), date_format(l.date_added, &quot;%H:%i&quot;) as &quot;time&quot;');
              $builder-&gt;join('users as u', 'l.u_id = u.u_id');
              $builder-&gt;join('establishment as e', 'l.e_id = e.e_id');
              $builder-&gt;where('DATE(l.date_added)', $rep_date);
              $builder-&gt;groupBy('date_format(l.date_added, &quot;%H:%i&quot;), l.u_id');
              $data['logs_data'] = $builder-&gt;get()-&gt;getResult();
  
          $this-&gt;load-&gt;view('list-logs',$data);
          //echo &quot;&lt;pre&gt;&quot;;
          //print_r($data);
  
      }
  </code></pre>
  <p>VIEW</p>
  <pre><code>&lt;?php
  
  
  if ($logs_data) {
      foreach ($logs_data as $row) {
          
          echo '
          &lt;tr&gt;
            &lt;td&gt;' . $row['date_added'] . '&lt;/td&gt;
            &lt;td&gt;' . $row['lname'] . &quot;, &quot; . $row['fname'] . &quot;, &quot; . $row['mname'] . '&lt;/td&gt;';
          
          if ($row['user_type'] == 'S') {
              echo '&lt;td&gt;STUDENT&lt;/td&gt;';
          } else if ($row['user_type'] == 'E') {
              echo '&lt;td&gt;EMPLOYEE&lt;/td&gt;';
          } else if ($row['user_type'] == 'P') {
              echo '&lt;td&gt;VISITOR&lt;/td&gt;';
          }
          
          if ($row['dept'] == 'GS') {
              echo '&lt;td&gt;GRADE SCHOOL&lt;/td&gt;';
          } else if ($row['dept'] == 'JHS') {
              echo '&lt;td&gt;JUNIOR HIGH SCHOOL&lt;/td&gt;';
          } else if ($row['dept'] == 'SHS') {
              echo '&lt;td&gt;SENIOR HIGH SCHOOL&lt;/td&gt;';
          }
          
          echo '&lt;/td&gt;
          &lt;td&gt;' . $row['u_grdsec'] . '&lt;/td&gt;';
      }
  }
  
  ?&gt;
  </code></pre>