2010年5月24日 星期一

define SaveToSQL interface

class ISaveToSQL {
    function GetField()
    {
        echo "hi... go back to study PHP 3 year!";
    }
}
class cucustom extends ISaveToSQL{
    ....

    function GetField()
    {
        $this->field["name"] = $this->name;
        $this->field["tel"] = $this->tel;
        $this->field["address"] = $this->address;

        return $this->field;
    }
}
class CuModelSave extends model
{
    function insertSaveToSQL(/*ISaveToSQL*/ $ISaveToSQL)
    {
        $this->db->insert($this->table_name, $ISaveToSQL->GetField());
    }
}
class custom_sql extends CuModelSave{
    ...
}

1 則留言:

  1. 繼承介面 ISaveToSQL 實作 GetField, 在model 裡也實作機制 CuModelSave 提供一個接口給 ISaveToSQL, 簡單的提取, 就能活用, 擴充.

    回覆刪除