Module system |
[eluser]daveario[/eluser]
For my latest work I need an extensible module system for CI. A module has to handle database connections and views. The only problem is: A module controller extends a model. If I want to address a function that displays a page, I am doing it with another controller who analyses the url, for example: Code: modulename/page But I can't call the function because the module name is a variable. Code: $this->MODULENAME->FUNCTION(); Do you know how to solve that? Thanks in advance!
[eluser]Jondolar[/eluser]
You load the module and then create an object. You then call the object's method. include('modulename.php'); $myObj = new modulename; $myObj->function(); Something like that, anyway.
[eluser]daveario[/eluser]
Thanks for the help, I don't know whether it will work but I'll try it as soon as I'm on my other computer.
[eluser]Phil Sturgeon[/eluser]
Why do you want the module name to dictate which model to use? What is the end goal of this app? Explain that one a bit and I can give you some help.
[eluser]daveario[/eluser]
It will be a content management system. A module will add a feature, like ›Blog‹ or ›Pages‹, the prepacked modules. All modules in a folder will automatically be loaded by CI.
[eluser]Eric Barnes[/eluser]
The way I do which you can see the full code if you download 68kb is to create a custom events library. What this does is allow me to add hooks into the code and then any modules plug into the hooks that particular module needs to use. I also allow for custom pages, installation, etc.. http://68kb.com/user_guide/developer/modules.html
[eluser]Phil Sturgeon[/eluser]
Well why the heck are you doing it like that? Google search for "CodeIgniter Modules" and the first 4 links give you perfectly good working answers that all maintain HMVC and are a bunch more logical. Google is your friend. :-)
[eluser]Jelmer[/eluser]
I'm not sure if I understand exactly what you want but the bottom line is that you want to dynamicly choose both the module and function, right? Which you tried doing like: [quote author="daveario" date="1249597401"] Code: $this->$module->$function(); # doesn't work. And that probably didn't work because PHP doesn't know which variable to resolve first or last, it could be ($this->$module)->$function or $this->($module->$function). You can solve that by using accolades: Code: $this->{$module}->{$function}() I'm not entirely sure if I used them right (I've only used this twice before a while ago), but this is the general direction.
[eluser]daveario[/eluser]
Thank you for your answers, that really helped me! I haven't known that such a system is really called module system so I haven't searched google yet. The first result seems perfect for what I want to do.
[eluser]Phil Sturgeon[/eluser]
It's always worth Googling dude, it is a free service and takes about 3 seconds. If I want to know anything about anything I do not already know, I write it in that little box in the top right, hit enter and then normally I find it straight away. If not, then I ask other people for help. Google takes 5 seconds, forum replies can be hours or even days! |
Welcome Guest, Not a member yet? Register Sign In |