2011-06-25 93 views
0

我的应用程序结构:如何扩展多个类

E:\ WAMP \ WWW \手机\模块\ mod_expense.php类名称:mod_expense Descrition:包含INSERT,DELETE,UPATE操作,也该CLAS延伸con_class CLASS

E:\瓦帕\ WWW \移动\控制器\ contr_busniss.php类名:con_class描述:内含选择查询的业务逻辑

E:\瓦帕\ WWW \移动\视图\ expenditure \ expense.php说明:包含expense.html CLASS和contr_busniss.php CLASS目的:使用此文件应用程序运行例如,如果要显示费用ADD FORM,那么我的URL看起来像似乎是http:// localhost/mobile/view/expenditure/?expense.php FP =添加 费用,查看表单,然后我的URL看起来likg http://localhost/mobile/view/expenditure/expense.php?fp=view

E:\ WAMP \ WWW \手机\图\支出\ expense.html.php类名称:expense_html_form描述:包含FORM(添加费用,编辑费用,查看费用)以及此类扩展con_class CLASS

现在我有Database类:CLASS Name是DB_Class ,我想在mod_expense.php & expense.html.php中使用这些类函数,我不太熟悉OOPS,

当前这些文件已经扩展了con_class CLASS,现在我想扩展Database类,如何延长DB类在这里,

我很少在这里摘录:

文件名:expense.php

include("../../include/config.php"); 
include("../../include/dbclass.php"); 
include_once("expense.html.php"); 
include("../../controller/con_error.php"); 
include_once("mod_expense.php"); 
$obj_dbclass = new dbClass(); 
$obj_dbclass->db_connect(); 


$expense_object = new expense_html_form(); 
$expense_object->expense_add(); 
if(isset($_POST['submit'])){ 
    $mod_expense = new mod_expense(); 
    echo $mod_expense->ins_expense(); 
} 

费尔Ë名称:expense.html.php

class expense_html_form{ 

    function expense_add(){ 
     ADD FORM 
    } 
} 

文件名:mod_expense.php

class mod_expense extends con_class{ 
    function ins_expense(){ 
     EXPENSE ADD FUNCTIONALITY 
    } 
} 

文件名:contr_busniss.php

class con_class{ 

    function check_already_exist($amount){ 
echo "SELECT expense_amount FROM expense WHERE expense_amount = '$amount'"; 
     $select=mysql_query("SELECT count(expense_amount) FROM expense WHERE expense_amount = '$amount'"); 
       $row=mysql_fetch_array($select); 
       $op=$row[0]; 
       return $op; 
    } 
} 

现在我想延长DBClass函数。建议如何实现。

+2

问题太长了。 –

+0

简单的如何实现当我们想要扩展多个类 – vlk

+1

PHP不支持多继承,如果这是你正在寻找的。看看[这个问题](http://stackoverflow.com/questions/3889080/php-oop-structure-problem-simulate-multiple-inheritance)。 – Jon

回答

0

我想也许你正试图完成太多的继承,当组成会更好的为你的情况。您可以将对$dbClass的引用传递给您的控制器,以便他们可以访问数据库功能。

从您的课程名称中,我假设您正在尝试使用Model-View-Controller,在这种情况下,我建议您不要将DB_class功能暴露给expense_html_form。您应该在您的控制器中执行任何必要的计算,并将最终结果提供给视图。

如果你绝对必须使用继承,有expense_html_formcon_class延长DB_class会暴露这些方法来expense_html_formmod_expense