Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeIgniter - Undefined variable & Trying to get property of non-object
    primarykey
    data
    text
    <p>I'm trying to get data from API in my Controller and pass the data to the View. But it don't seem working and causing error:</p> <p><strong>Message:Undefined variable: data</strong> and <strong>Message:Trying to get property of non-object</strong></p> <p>Both errors happen in my View.php, on the line when I call variable $data.</p> <p>This is part of my controller related to data I want to get</p> <pre><code>$jdwl['jadwal'] = $this-&gt;bolalob-&gt;api('schedules/bydate|'.$start.'/'.$end.'/10'); $data['jadwal'] = $this-&gt;load-&gt;view('jadwal', $jdwl, TRUE); $template['content'] = $this-&gt;load-&gt;view('jadwal',$data, TRUE); $this-&gt;load-&gt;view('template', $template); </code></pre> <p>And this is my view </p> <pre><code>&lt;div class="float-left first-column"&gt; &lt;div class="box box-shadow red round-top round-bottom"&gt; &lt;div class="title-box"&gt;&lt;strong&gt;JADWAL&lt;/strong&gt; TV&lt;/div&gt; &lt;ul class="text-center no-padding"&gt; &lt;?php if ($data-&gt;data == 'no data') { ?&gt; &lt;li class="jadwal-tv"&gt;&lt;strong&gt;Belum ada jadwal&lt;/strong&gt; &lt;/li&gt; &lt;?php } else { ?&gt; &lt;?php foreach ($data-&gt;data as $key=&gt;$row) { ?&gt; &lt;?php if ($key == 0) { ?&gt; &lt;li class="jadwal-tv"&gt;&lt;strong&gt;&lt;?php echo $row-&gt;team_1-&gt;name; ?&gt;&lt;/strong&gt;&lt;br /&gt;VS&lt;br /&gt;&lt;strong&gt;&lt;?php echo $row-&gt;team_2-&gt;name; ?&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span&gt;&lt;?php echo $row-&gt;television; ?&gt; &lt;?php echo date('d/m/y H:i', $row-&gt;pubdate); ?&gt; WIB&lt;/span&gt;&lt;/li&gt; &lt;?php } else { ?&gt; &lt;li class="side-padding"&gt; &lt;strong&gt;&lt;?php echo $row-&gt;team_1-&gt;name; ?&gt;&lt;/strong&gt; vs &lt;strong&gt;&lt;?php echo $row-&gt;team_2-&gt;name; ?&gt;&lt;/strong&gt; &lt;br /&gt; &lt;?php echo $row-&gt;television; ?&gt; &lt;?php echo date('d/m/y H:i', $row-&gt;pubdate); ?&gt; WIB &lt;/li&gt; &lt;?php } ?&gt; &lt;?php if ($key == 5) break; ?&gt; &lt;?php } ?&gt; &lt;?php } ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>The error happens to $data on line the 5 and 9. I've googled it and tried to use $data['jadwal'] instead of $data in my view but I didn't seem working too.</p> <p>Anyone can help me with this? Thanks :D</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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