I have turned a normal PHP class into a library so I can use it in Codeigniter as a library. I can load it and call the funct开发者_开发百科ions I need in that class. Here is that class to help with the question.
However, there are quite a few points where I have to call functions in my class. These functions reside in the model that instantiated my class. How can I do this as currently normal calls don't work. Here is my code:
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"];
}
}
Thanks all for any help.
Just to clarify, you are having problems calling the model's functions passed to your bookmarkparser?
Within your Library, you'll need to reference the Model itself and it's functions via:
// Based on the signature you provided
parseNetscape($url, $folderID, $urlFunction, $folderFunction) {
get_instance()->Controlpanel_model->$urlFunction();
get_instance()->Controlpanel_model->$folderFunction();
}
We need to use get_instance() since Libraries don't inherit all the CI goodies. This will assume that your model has already been loaded. I'm not sure what you were having problems with, referencing the $CI instance or dynamically calling functions.
Hope that's what you were looking for.
精彩评论