[eluser]BenSeagrave[/eluser]
I googled how to pass 2 variables to your view file and someone told me to make an assoc array and include the variables inside of the array and pass the assoc array to the view. But i'm getting an error, Can someone tell me what i'm doing wrong?
Here is my controller :
Code:
<?php
class Site extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$pageInfo = array(
'main_content' => 'home_view',
'document_title' => 'Home'
);
if($query = $this->site_model->getRecords())
{
$dbData['records'] = $query;
}
$data = array(
'pageInfo' => $pageInfo,
'dbData' => $dbData
);
$this->load->view('includes/template', $data);
}
}
?>
The includes/template view file is just:
Code:
<?php
$this->load->view('includes/header');
$this->load->view($main_content);
$this->load->view('includes/footer');
?>
This worked before I had the assoc array passing both the varibles.
and this is the part of the view file that is loaded as the main_content at the moment:
Code:
<article>
<?php if(isset($records)) : foreach($records as $row): ?>
<h2>
<?=echo $row->title;?>
<h6>Posted on <strong><?=echo $row->date;?></strong> at <strong><?=echo $row->time;?></strong> | 10 Comments</h6>
<p><?=echo $row->body;?></p>
</h2>
</article>
This is only a snippet of the main content as the rest of the file is pointless.
The error i'm getting from my browser is:
A PHP ERROR WAS ENCOUNTERED
Severity: Notice
Message: Undefined variable: main_content
Filename: includes/template.php
Line Number: 5
I don't understand what is wrong!! Can someone help