Interaction between classes
Posted: Sat Jun 03, 2006 12:27 pm
Hey All,
I am building a site and, as Im looking to develop my OOP skills, have decided to do the majority in OOP. So far I have a templating class (works), an SQL layer (working so far), and a site maitenance class (AAAANT!).
My index.php looks like this:
I use the $mysql->query() function I made in the SQL layer in the maitenance.class file, but when I try to execute the getNews() func, I get an 'atal error: Call to a member function on a non-object' error
Now the class is initialized (the sql layer) before it is used in the maitenance file and the DB connect and select are executed before as well (and tested, there is a full connection to the MySQL server)
Now in the getNews() func I have this:
Note the use of the $mysql->query()
Question: Is there a specific action to perform to have 2 classes interact?
Thanks and sorry for the long post
I am building a site and, as Im looking to develop my OOP skills, have decided to do the majority in OOP. So far I have a templating class (works), an SQL layer (working so far), and a site maitenance class (AAAANT!).
My index.php looks like this:
Code: Select all
include('classes/template.class.php');
include('classes/mysql.class.php');
include('classes/maitenance.class.php');
// template + modular code here
$ops->getNews();
// template code hereNow the class is initialized (the sql layer) before it is used in the maitenance file and the DB connect and select are executed before as well (and tested, there is a full connection to the MySQL server)
Now in the getNews() func I have this:
Code: Select all
function getNews()
{
$mysql->query('SELECT * FROM ' . $this->news_table . ' LIMIT '. $this->num_news, $sql) or die (mysql_error());
$output = '';
while ($row = mysql_fetch_array($sql))
{
$output .= "<h2>{$row['title']} - {$row['date']}</h2>";
$output .= "<p>{$row['maintext']}</p>";
$output .= "<hr /><br />";
}
return $output;
}Question: Is there a specific action to perform to have 2 classes interact?
Thanks and sorry for the long post