Undefined variable when integrating PHPExcel with CodeIgniter
<p>I'm new to OOP and also CodeIgniter. Started a day ago with the basic example of Pages Controller and pages. Now I need to integrate with PHPExcel. Here is my controller:</p>

<pre><code>&lt;?php

class Report extends CI_Controller {
    public function __construct() {
        parent::__construct();
    }

    public function readReport() {
        $file = APPPATH."/third_party/teste.xlsx";
        //load the excel library
        $this-&gt;load-&gt;library('excel');
        //read file from path
        $objPHPExcel = PHPExcel_IOFactory::load($file);
        //get only the Cell Collection
        $cell_collection = $objPHPExcel-&gt;getActiveSheet()-&gt;getCellCollection();
        //extract to a PHP readable array format
        foreach ($cell_collection as $cell) {
            $column = $objPHPExcel-&gt;getActiveSheet()-&gt;getCell($cell)-&gt;getColumn();
            $row = $objPHPExcel-&gt;getActiveSheet()-&gt;getCell($cell)-&gt;getRow();
            $data_value = $objPHPExcel-&gt;getActiveSheet()-&gt;getCell($cell)-&gt;getValue();
            //header will/should be in row 1 only. of course this can be modified to suit your need.
            if ($row == 1) {
                $header[$row][$column] = $data_value;
            } else {
                $arr_data[$row][$column] = $data_value;
            }
        }
        //send the data in an array format
        $data['teste'] = "Rodrigo";
        $data['header'] = $header;
        $data['values'] = $arr_data;
        $this-&gt;load-&gt;view('pages/home', $data);
        }
}
</code></pre>

<p>Here is my view:</p>

<pre><code>&lt;!-- Page Content --&gt;
&lt;div id="page-content-wrapper"&gt;
    &lt;div class="container-fluid"&gt;
        &lt;div class="row"&gt;
            &lt;div class="col-lg-12"&gt;
                &lt;?php echo $teste; ?&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;!-- /#page-content-wrapper --&gt;
</code></pre>

<p>Pages Controller:</p>

<pre><code>&lt;?php

class Pages extends CI_Controller {
    public function view ($page = 'home') {
        if (!file_exists(APPPATH.'views/pages/'.$page.'.php')) {
            show_404();
        }

        $data['title'] = str_replace("_", " ", $page);

        $this-&gt;load-&gt;helper('url');
        $this-&gt;load-&gt;view('templates/header', $data);
        $this-&gt;load-&gt;view('pages/'.$page, $data);
        $this-&gt;load-&gt;view('templates/footer', $data);
    }
}
</code></pre>

<p>Error message:</p>

<pre><code>A PHP Error was encountered

Severity: Notice

Message: Undefined variable: teste

Filename: pages/home.php

Line Number: 6

Backtrace:

File: C:\xampp\htdocs\PhpProject3\application\views\pages\home.php
Line: 6
Function: _error_handler

File: C:\xampp\htdocs\PhpProject3\application\controllers\Pages.php
Line: 13
Function: view

File: C:\xampp\htdocs\PhpProject3\index.php
Line: 315
Function: require_once
</code></pre>

<p>Can someone help what am I doing wrong here?</p>