Forum Moderators: coopster

Message Too Old, No Replies

in one class run many class, PHP OOP

         

Lolalola

9:48 pm on Dec 20, 2010 (gmt 0)



Hi,

i have class "User_registration" and in this class i need use many class: "Location", "Links", "Mail", "Module".

i create include all class in file: include 'class/location.php'; include 'class/links.php'; include 'class/mail.php'; include 'class/modules.php';

Now create "User_registration" class.

<?php
class User_registration{

public function insert_to_db($name, $country_code, $home_page)
{
//work with data

return id;
}

public function show_info($id)
{
//work with data
}
}

$reg_u = new User_registration;
$res = $reg_u->insert_to_db($name, $country_code, $home_page);

if($res){
$reg_u->show_info($res);
}
?>


I need in method "insert_to_db" run class: "Location", "Links", "Mail" methods and in "show_info" run some methods of "Location", "Links", "Module" class.

How? How in one class run another class (no't one)

Thanks for help

coopster

8:00 pm on Dec 30, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are bumping into a Scope Resolution [php.net] issue, more than likely. However, it looks like you are creating the Database class layer inside another class. Rather than invoke the method statically I would recommend making your Database class a Singleton pattern [php.net] in a class of it's own.