-1

I am just new to CodeIgniter and i encounter a PHP error -

Severity: Notice Message: Undefined variable

My Controller : C:\wamp\www\Code1\application\config\hello.php

<?php
class Hello extends Controller {

    var $name;
    var $color;

    function Hello()
    {
        parent::Controller();       
        $this->name = 'Andi';
        $this->color= 'red';
    }

    function you()
    {
        $data['name'] = $this->name;
        $data['color'] = $this->color;
        $this->load->view('you_view', $data);
    }
}
?>

My Views : C:\wamp\www\Code1\application\views\you_view.php

Hello, 
<font color="<?=$color?>"><?=$name?></font>!
Machavity
  • 29,816
  • 26
  • 86
  • 96

1 Answers1

1

first: the construct function in php is not the same name of it's classname. so change your construct function like this:

function __construct()
{
    parent::__construct();       
    $this->name = 'Andi';
    $this->color= 'red';
}

then ,For ease of understanding,please put your controller file under application/controllers files!

smallerpig
  • 27
  • 5