簡體   English   中英

如何擴展多班

[英]How to extends multiple class

我的應用程序結構:

E:\\ wamp \\ www \\ mobile \\ module \\ mod_expense.php類別名稱:mod_expense描述:包含INSERT,DELETE,UPATE操作,並且此類擴展了con_class CLASS

E:\\ wamp \\ www \\ mobile \\ controller \\ contr_busniss.php類名:con_class說明:包含選擇查詢業務邏輯

E:\\ wamp \\ www \\ mobile \\ view \\ expenditure \\ expense.php說明:包含expense.html CLASS和contr_busniss.php CLASS用途:例如,如果要顯示Expense ADD FORM,則運行此應用程序,然后顯示我的URL看起來輕巧的http://localhost/mobile/view/expenditure/expense.php?fp = add費用查看表格,然后我的網址看起來輕巧的http://localhost/mobile/view/expenditure/expense.php?fp = view

E:\\ wamp \\ www \\ mobile \\ view \\ expenditure \\ expense.html.php類別名稱:expense_html_form說明:包含表單(ADD費用,編輯費用,查看費用),並且此類擴展了con_class CLASS

現在我有數據庫類:CLASS Name是DB_Class,我想在mod_expense.php和expense.html.php中使用這些類函數,我對OOPS不太熟悉,

目前,這些文件已經擴展了con_class CLASS,現在我想擴展Database類,如何擴展DB CLASS,

我的摘要在這里很少:

文件名: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函數。 建議如何實現。

我認為也許當組合對於您的情況更好時,您可能會嘗試在繼承方面完成太多工作。 您可以$dbClass的引用傳遞給控制器​​,以便它們可以訪問數據庫功能。

從類的名稱中,我假設您正在嘗試使用Model-View-Controller,在這種情況下,我建議您不要將DB_class功能公開給expense_html_form 您應該在控制器內執行任何必要的計算,並將最終結果提供給視圖。

如果您絕對必須使用繼承,則使expense_html_formcon_class擴展DB_class會將這些方法公開給expense_html_formmod_expense

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM