开发者

How to extends multiple class

开发者 https://www.devze.com 2023-03-15 03:36 出处:网络
my application structure: E:\\wamp\\www\\mobile\\module\\mod_expense.php CLASS NAME: mod_expense Descrition : contains the INSERT,DELETE,UPATE Operationand also this clas extends con_class CLASS

my application structure:

E:\wamp\www\mobile\module\mod_expense.php CLASS NAME: mod_expense Descrition : contains the INSERT,DELETE,UPATE Operation and also this clas extends con_class CLASS

E:\wamp\www\mobile\controller\contr_busniss.php CLASS NAME: con_class Description: Contain the select query business logics

E:\wamp\www\mobile\view\expenditure\expense.php Description: Contains the expense.html CLASS and contr_busniss.php CLASS Purpose: With this file Application running for example if want to display the Expense ADD FORM , then my URL looks likg http://localhost/mobile/view/expenditure/expense.php?fp=add Expense VIEW FORM , then my URL looks likg http://localhost/mobile/view/expenditure/expense.php?fp=view

E:\wamp\www\mobile\view\expenditure\expense.html.php CLASS NAME: expense_html_form Description: Contains the FORM (ADD Expense, Edit Expense, View Expense) and also this clas extends con_class CLASS

Now i have Database class: CLASS Name is DB_Class, i want to use these class functions in mod_expense.php & expense.html.php , i am not much femiliar with OOPS,

Currently these file are already extends the con_class CLASS, Now i want to extends the Database class, How to extend the DB CLASS Here,

Few my snippet here:

File name : 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();
 }

File name : expense.html.php

class expense_html_form{

    function expense_add(){
        ADD FORM
    }
}

File Name: mod_expense.php

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

File Name: 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'");
        开发者_StackOverflow社区        $row=mysql_fetch_array($select);
                $op=$row[0];
                return $op;
    }
}

Now i want extends the DBClass function. Advise how to achieve.


I think maybe you're trying to accomplish too much with inheritance when composition would be better for your situation. You could pass a reference to $dbClass to your controllers so they have access to database functionality.

From the names of your classes I assume that you're trying to use Model-View-Controller, in which case I would recommend against exposing the DB_class functionality to expense_html_form. You should instead perform any necessary calculations within your controllers and give the end result to the view.

If you absolutely must use inheritance, having expense_html_form and con_class extend DB_class would expose those methods to expense_html_form and mod_expense.

0

精彩评论

暂无评论...
验证码 换一张
取 消