Welcome Guest, Not a member yet? Register   Sign In
Passing 2 Variables to your view error
#1

[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>
        &lt;?php if(isset($records)) : foreach($records as $row): ?&gt;
        <h2>
        &lt;?=echo $row->title;?&gt;
        <h6>Posted on <strong>&lt;?=echo $row->date;?&gt;</strong> at <strong>&lt;?=echo $row->time;?&gt;</strong> | 10 Comments</h6>
        <p>&lt;?=echo $row->body;?&gt;</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 Tongue


Messages In This Thread
Passing 2 Variables to your view error - by El Forum - 07-25-2011, 06:58 PM
Passing 2 Variables to your view error - by El Forum - 07-25-2011, 10:04 PM
Passing 2 Variables to your view error - by El Forum - 07-25-2011, 10:13 PM



Theme © iAndrew 2016 - Forum software by © MyBB