-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
  • 30,841
  • 27
  • 92
  • 100

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
  • I encounter another eror following your advise @smallerpig A PHP Error was encountered Severity: Error Message: Class 'Controller' not found Filename: controllers/hello.php Line Number: 2 Backtrace: – Manuel Sebastian Sanchez May 06 '15 at 01:58
  • please put your hello.php under application/controllers files and change the filename to Hello.php. and change the parent class to CI_Controller – smallerpig May 06 '15 at 02:04
  • Is my pleasure to help you!@ManuelSebastianSanchez – smallerpig May 06 '15 at 02:12