Reflection in CI |
[eluser]dsloan[/eluser]
Has anyone had experience of, or found a need to consider, the idea of reflection within CI controllers or models, i.e. to determine at any time from within the code, which class and method the code is currently executing? Let me explain the scenario... I'm investigating the possibility of having a hooks-type approach to functionality within one of our own applications, whereby a "product"s core functionality can be extended for particular clients if the need arises. This would allow us to have a safe upgrade path for all users of the core application product, but still offer customisation where necessary. I've read several existing forum entries on this, such as http://ellislab.com/forums/viewthread/63832/ but decided to try a simple approach myself. What I'm trying to do is at all entry/exit points in controller methods to have a generic method which will determine the current context and look up another config-type file to determine if any custom code needs to be executed. Or has someone a better idea? It's really applying the CI hooks concept to extend core CI functionality, to my own application's functionality.
[eluser]tonanbarbarian[/eluser]
ok firstly you can determine what is being run using the router object Code: $this->uri->router->directory // directory that is being called otherwise / As for what you are trying to do why not simple add named hook points into your code to allow the clients to extend it. SO if you want to create a hook point in your code called "blah" Code: $EXT =& load_class('Hooks'); Note I have not tried this but in theory it should work. Once I have finished a project I am working on at the moment I will be looking at doing this to the project to further extend it. You should just have to make sure that you name the hook points something meaningful and unique
[eluser]dsloan[/eluser]
Thanks for your very helpful reply - both of those will work, I'll pursue the hooks approach for now, which seems tidier and more logical. |
Welcome Guest, Not a member yet? Register Sign In |