Why am I getting the following errors
A PHP Error was encountered Severity: Warning Message: Undefined variable: json Filename: views/search_page.php Line Number: 8
A PHP Error was encountered Severity: Warning Message: Trying to get property of non-object Filename: views/search_page.php Line Number: 8
A PHP Error was encountered Severity: Warning Message: Invalid argument supplied for foreach() Filename: views/search_page.php Line Number: 8
with this code?
search.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Search extends CI_Controller {
public function index()
{
$json = json_decode(file_get_contents('http://search.twitter.com/search.json?q=to%3astackexchange'));
$this->load->view('search_page', $json);
}
}
/* End of file search.php */
/* Location: ./application/controllers/search.php */
search_page.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Twitter Test</title>
</head>
<body>
<?php foreach ($json->results as $result): ?>
<h2><?php echo $result->from_user; ?></h2>
<?php endforeach ?>
</body>
</html>