• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Notice error while adding a new controller

#1
[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

#2
[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.

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.