Welcome Guest, Not a member yet? Register   Sign In
Undefined property: Index::$load
#1

[eluser]Bl4cKWid0w[/eluser]
I just started to develop a new site with CI. For now, I only have three view files loaded on my index pages which are made strictly with HTML. When I visit the index page, I get the following error:

CI Error:
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Index::$load

Filename: controllers/index.php

Line Number: 7

PHP Error:
Quote:Fatal error: Call to a member function view() on a non-object in /home/unholy/public_html/blackdiamondgaming/system/application/controllers/index.php on line 7

My Index.php page:
Code:
<?php

class Index extends Controller {
    
    function index(){
        
            $this->load->view('overall_header');
            
            $this->load->view('index_body');
            
            $this->load->view('overall_footer');
            
    }
    
}

Any one have any ideas?
#2

[eluser]bastones[/eluser]
It may be because your index controller is called Index.php instead of index.php, but try it as a different file name in the Controller and changing the class Index too, and see if it works.
#3

[eluser]Michael Wales[/eluser]
It's because you didn't include the constructor:

Code:
function Index() {
  parent::Controller();
}
#4

[eluser]Bl4cKWid0w[/eluser]
Thanks, Mike, that was it.
#5

[eluser]Bl4cKWid0w[/eluser]
Another weird occurrence... now the page is being displayed twice. The HTML is being displayed twice.
#6

[eluser]bastones[/eluser]
[quote author="Bl4cKWid0w" date="1228842920"]Another weird occurrence... now the page is being displayed twice. The HTML is being displayed twice.[/quote]

It may be because you have the load->view section in the parent constructor (which the function that is identical to your controller name the bit with the parent::Controller), remember that the parent controller applies anything to every other function including the index() function so for example if you had an echo statement in the parent constructor you'll see that echo on every page of your site.

You can visit this section for more information about controllers and specifically constructors at the bottom of that page.

PS: Remember that if you include the load->view function twice anywhere in the same function or in one function AND the constructor, it'll load the view file twice Smile.
#7

[eluser]Unknown[/eluser]
Thank you mike for everything. we can also use parent::__construct();




Theme © iAndrew 2016 - Forum software by © MyBB