Welcome Guest, Not a member yet? Register   Sign In
Calling a model function from within a plugin
#1

[eluser]Bob Sawyer[/eluser]
Sorry if this has been posted elsewhere; I searched for several different variations of the title and couldn't find anything. Anyway...

I am creating a fairly specialized CMS for a vertical market, and want to make it extensible with plugins. Instead of creating a whole separate plugin scheme, I am dropping all of the CMS plugins into a subfolder of the CI plugins directory.

By and large, these plugins will be fairly simple, however, at least one needs to access the database. Since plugins are not object-oriented, $this->db->whatever does not work. I'm already auto-loading the model, so simply including it the old fashioned way creates a second instance of the model class.

So, I'm a little bit lost here. Is it possible to call a model from within a plugin, and if so, what's the correct syntax?

Thanks,
Bob
#2

[eluser]Bob Sawyer[/eluser]
Well, I may have solved this, at least temporarily. The one plugin that required db access contained a function that could just as easily have been included in my controller. So that one's fixed.

Still, the question remains, as I've run into this before: is it allowed, or, if db access is necessary, is it better off being included in the controller?
#3

[eluser]Randy Casburn[/eluser]
Nothing stopping you from creating an instance of the CI super object:

$CI =& get_instance();

That gives you access to $CI->load. Then you have access to your models or DB or whatever. Not sure thats good design at all, but hey, with a title like that, who am I to argue ;-)

Randy
#4

[eluser]Bob Sawyer[/eluser]
hehehe, indeed. That's true, hadn't thought about the CI super object.

Thanks,
Bob




Theme © iAndrew 2016 - Forum software by © MyBB