Welcome Guest, Not a member yet? Register   Sign In
Having a problem with $this->load->view();
#1

[eluser]ConnorD[/eluser]
Hi,

I am fairly experienced in PHP, but brand new to CI, so please bare with me. I have been having no trouble until I tried to load a view from my controller:

Code:
<?php
class Home extends Controller{
    function index(){
        parent::Controller();
    }
    function Home(){
        $data['title'] = "Livefootballtalk - Home";
        $data['intro'] = "Livefootballtalk is a soccer/football fan community where fans from all different countries and clubs can meet and discuss about world football competitions and players. Also, the fans may interact through their profile pages and messager. We invite you to be a real fan and <a href='register.php?step=1'>join</a> the community!";    
        
        
        $this->load->view('home', $data);
    }
}
?&gt;

I am getting an error message on my codeigniter page from my browser saying: "A PHP Error was encountered

Severity: Notice

Message: Undefined property: Home::$load

Filename: controllers/home.php

Line Number: 11".

I don't understand it, because I have done everything with the tutorials. Any help would be appreciated, thank you.

BTW, here is my view if it is of interest:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;link rel="stylesheet" href="css/1.css" type="text/css" media="screen,projection" /&gt;
&lt;/head&gt;
&lt;body&gt;

        <div id="top">
        
        </div>
        
        <div id="container">
        
                <div id="menu">
                
                        <ul id="nav">

                        &lt;?php
                        
                        ?&gt;
                        
                        </ul>
                        
                        <br class="clear" />
                
                </div>
                
                
                
                <div id="sidebar">
                
                        <h1 class="first">
                        
                            Home
                        
                        </h1>
                        
                        <p>
                        
                        
                        </p>
                        
                        <h1>My Account</h1>
                        
                        <ul class="linkroll">
                        
                            &lt;?php
                            
                            ?&gt;

                            
                        </ul>
                        
                    
                
                </div>
                
                <div id="content">
                &lt;?php
                
                ?&gt;
                <br />
                
                        <h1>Welcome to Livefootballtalk!</h1>
                        <br />
                        <img src="../images/soccer_fans.jpg" width="380" height="280" /><br />
                        
                        <p>
                        &lt;?php
                        echo $intro;
                        ?&gt;
                        </p>
                        <br /><br />
                        &lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/dIlcc7Vks-8&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param>&lt;embed src="http://www.youtube.com/v/dIlcc7Vks-8&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed>&lt;/object&gt;    
                        </p>
                        <br />
                        &lt;?php
                        echo "<br><font color='black'>Latest Discussions:</font><br>";
                        foreach($threads_query->result() as $row){
                            echo "<table border='0'><tr><td>Subject: <br><br><a >subject'>$row->subject</a></td></tr><td><td>By: <a >username'>$row->username</a></td></tr></table></table><hr>";
                        }
                        ?&gt;
                </div>

                <div id="footer">
                    
                    <p>Copyright 2008 Livefootballtalk.com | <a href="mailto:[email protected]">[email protected]</a></p>        
        
                </div>
        
        </div>


&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]Sarfaraz Momin[/eluser]
Hi, it seems a very small mistake you made in the code. Check the code below.
Code:
&lt;?php
class Home extends Controller{
    function Home(){
        parent::Controller();
    }
    function index(){
        $data['title'] = "Livefootballtalk - Home";
        $data['intro'] = "Livefootballtalk is a soccer/football fan community where fans from all different countries and clubs can meet and discuss about world football competitions and players. Also, the fans may interact through their profile pages and messager. We invite you to be a real fan and <a href='register.php?step=1'>join</a> the community!";    
        
        
        $this->load->view('home', $data);
    }
}
?&gt;

You have the constructor name different than your class name which I have reversed. It should work now !!!

Have a good day !!!
#3

[eluser]ConnorD[/eluser]
Thank you for the quick response, it worked! Now that I have pretty much all of the main problems I am having with CI worked out, I am really beginning to like this FW. I am rewriting my whole site currently in CI (just started today), and I have already finished a few pages! I remember when I started my website originally in raw php, it took me days to even get where I am right now in CI!
#4

[eluser]Sarfaraz Momin[/eluser]
It indeed is cool stuff. There are a few personal recommendations though.
1. Whenever you have a problem please try to refer the user guide. Trust me it helped me most of the time for conventional things.
2. For issues which are not conventional or I should say is not related to usability problems then the next best thing you do is post here and this great community here would get you someone to help.

Have a good day !!!
Welcome and enjoy coding in CI !!! Smile
#5

[eluser]Randy Casburn[/eluser]
Hi Connor,

This indicates the CI super object is not available with this class. The reason is because you don't have a constructor.

Rename your index method to __constructor() or to Home() and things will be better.

[edit] -- well never mind - I was way slow on the response. Welcome to CI anyway!


Randy




Theme © iAndrew 2016 - Forum software by © MyBB