2010-03-28 45 views
0

我已經將普通的PHP類轉換爲庫,以便我可以在Codeigniter中將它用作庫。我可以加載它並調用我在該類中需要的函數。 Here is that class to help with the question從庫調用模型函數

但是,我不得不在我的班級中調用函數。這些函數駐留在實例化我的類的模型中。我目前的普通電話無法工作,我該如何做到這一點。這裏是我的代碼:


class Controlpanel_model extends Model { 

    var $category = ''; 
    var $dataa = 'a'; 

    function Controlpanel_model(){  

     parent::Model(); 

    } 

    function import_browser_bookmarks(){ 

     $this->load->library('BookmarkParser'); 
     /* 
     *In this function call to the class I pass 
     * what model functions exist that it should call 
     * You can view how this done by clicking the link above and looking at line 383 
     */ 
     $this->bookmarkparser->parseNetscape("./bookmarks.html", 0, 'myURL', 'myFolder'); 
     return $this->dataa; 

    } 

    function myURL($data, $depth, $no) { 

     $category = $this->category; 
     $this->dataa .= 'Tag = '.$category.'<br />'.'URL = '.$data["url"].'<br />'.'Title = '.$data["descr"].'<br />'.'<br /><br />'; 
    } 

    function myFolder($data, $depth, $no) { 

     $this->category = $data["name"]; 

    } 

} 

感謝所有的任何幫助。

回答

2

只是爲了澄清,你有問題調用模型的函數傳遞給你的bookmarkparser?

在你的圖書館,你需要參考模型本身,它通過的職能:

// Based on the signature you provided 
parseNetscape($url, $folderID, $urlFunction, $folderFunction) { 
    get_instance()->Controlpanel_model->$urlFunction(); 
    get_instance()->Controlpanel_model->$folderFunction(); 
} 

我們需要使用get_instance(),因爲庫不繼承所有的CI東西。 這將假定您的模型已經被加載。我不確定你遇到問題,引用$ CI實例或動態調用函數。

希望這就是你要找的。

+0

完美 - 正是我期待的! – Abs 2010-03-29 14:24:56