PHP Codeigniter Variable Scope Error

sality

I can't figure out why this code is outputting a Notice error

<?php

class Dashboard extends CI_Controller {   

    public $data = array();

    public function __construct() 
    {

        parent::__construct();
        $this->data['brand_title']   = 'Company Brand';

    }

    public function index()
    {
        echo $brand_title;
    }
}

I get a Undefined variable: brand_title error.

Terry Harvey

You can access it like this:

echo $this->data['brand_title'];

If you prefer your way, you could do it like this:

extract($this->data);
echo $brand_title;

But extract() is generally considered bad practice.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related