我有类“User_registration”,在这个类中我需要使用许多类:“位置”,“链接”,“邮件”,“模块”。在一个类中运行很多类,PHP OOP
我创建包含文件中的所有类: include'class/location.php'; 包含'class/links.php'; 包含'class/mail.php'; 包含'class/modules.php';
现在创建“User_registration”类。
<?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);
}
?>
我需要在方法“insert_to_db”跑班:“位置”,“链接”,“邮件”的方法 和“show_info”运行“位置”的一些方法,“链接”,“模块”类。
怎么样?如何在一个类中运行的另一个类(no't一个)
感谢您的帮助;)
您可以创建对象的一个实例并调用它们的方法,或者如果它适合使这些方法成为静态并静态调用它们。 – 2010-12-20 21:48:44