EllisLab text mark
Advanced Search
     
Undefined property: Index::$load
Posted: 08 December 2008 03:01 PM
Joined: 2008-07-15
77 posts

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:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Index::$load

Filename: controllers/index.php

Line Number: 7

PHP Error:

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:

<?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?

 
Posted: 08 December 2008 03:17 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2008-11-04
58 posts

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.

 
Posted: 08 December 2008 03:43 PM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-07-30
2144 posts

It’s because you didn’t include the constructor:

function Index() {
  parent
::Controller();
 Signature 

Follow me on twitter here.
MichaelWales.com | MichaelWales.info

 
Posted: 08 December 2008 04:45 PM   [ # 3 ]   [ Rating: 0 ]
Joined: 2008-07-15
77 posts

Thanks, Mike, that was it.

 
Posted: 09 December 2008 07:15 AM   [ # 4 ]   [ Rating: 0 ]
Joined: 2008-07-15
77 posts

Another weird occurrence… now the page is being displayed twice.  The HTML is being displayed twice.

 
Posted: 09 December 2008 09:07 AM   [ # 5 ]   [ Rating: 0 ]
Joined: 2008-11-04
58 posts
Bl4cKWid0w - 09 December 2008 12:15 PM

Another weird occurrence… now the page is being displayed twice.  The HTML is being displayed twice.

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.

 
Posted: 21 June 2012 06:27 AM   [ # 6 ]   [ Rating: 0 ]
Joined: 2012-03-21
1 posts

Thank you mike for everything. we can also use parent::__construct();