CodeIgniter Forums
Notice error while adding a new controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Notice error while adding a new controller (/showthread.php?tid=57463)



Notice error while adding a new controller - El Forum - 03-16-2013

[eluser]Unknown[/eluser]
I am new to the codeigniter. I just downloaded 2.1.3 and it works well. The welcome controller and view works. But when I added a new controller and view it showing an error.

Error looks like:
-----------------------
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Index::$load
Filename: controllers/index.php
Line Number: 7

Controller code:
------------------------
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Index extends CI_Controller {

public function index()
{
$this->load->view('welcome_message');
}

}

Not sure what this error is about. I have tried the same thing which was in welcome


Notice error while adding a new controller - El Forum - 03-16-2013

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

What's happening there is that your controller is called Index, and you have a method that's also called Index. PHP is assuming that index() is the constructor for your controller, and calling that.

if you add:
Code:
function __construct()
{
    parent::__construct();
}

it should work.


Notice error while adding a new controller - El Forum - 03-16-2013

[eluser]Unknown[/eluser]
Oh yeah it worked Smile Thanks very much.