0

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.

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

You can't use this like that in the same controller only in view of the same method you can use this

but if you want to use it like your post then it should be like that

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

Comments

0

The $brand_title variable doesn't exist. That's why it's generating the Undefined variable error. If you want to store it in a variable and use that, try this:

 public function index()
 {
     $brand_title = $this->data['brand_title'];
     echo $brand_title;
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.