• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Module system

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:
The controller knows which module is meant and which function it should call.

But I can't call the function because the module name is a variable.


$this->$module->$function(); # doesn't work.

Do you know how to solve that?
Thanks in advance! Smile

You load the module and then create an object. You then call the object's method.

$myObj = new modulename;

Something like that, anyway.

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. Smile

[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.

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..

[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. :-)

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"]
$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:

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.

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!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.