Welcome Guest, Not a member yet? Register   Sign In
Matchbox callers and _remap
#1

[eluser]tonanbarbarian[/eluser]
I am developing a CRUD library to use in building a number of apps
To facilitate development I decided to use Matchbox so that I could have each of the apps as a seperate module on the development site and they could all share the CRUD libraries in the base of the site, as well as having my apps "module aware" so that I know they can run both in and outside of matchbox

so quick run down of the layout

Code:
/application
  /libraries
    crud.php  - main crud controller library
    crud_index.php - crud index library
    crud_edit.php - crud edit and add library
    crud_delete.php - crud delete library
    MY_Controller.php - extends the controller to call the crud.php if needed
    Matchbox.php
  /modules
    /app1
      /controllers
        app1.php
    /app2
      /controllers
        app2.php

So the Matchbox and crud libraries are in the root libraries location.
Now the MY_Controller uses _remap and some checking code to determine if the controllers (e.g. app1.php) needs to perform a crud operation and if so it loads the appropriate crud library

So for example if we are adding a new record, then the MY_Controller is loaded and whichever controller is being called, e.g. app2.php
Because the MY_Controller has a _remap in it the remap is run and that looks at a property of the app2.php which is an array of the methods to crud. If the current method is in the list of crud method then it loads the crud library crud.php and calls the method. crud.php then has its own internal methods for each of the crud actions and it then loads the sub library e.g. crud_edit.php and that does most of the work. crud_edit.php will occasionally look in the model or controller for methods to help it do its work.

Now the issue with this is that Matchbox uses a debug_backtrace to determine what has called the current function and tries to work its way back through that information to determine which module it is in.

But if you look at what is happening when the crud is working it is never called directly from app2.php but rather from MY_Controller, so it never determines what the module is and therefore it cannot load any module specific model, libraries, views etc.

Now while I have a solution of sorts, by adding another _remap to the app2.php that calls the parent::_remap, it is not my preferred solution. I also have to add a LOT of callers, which I do in code rather than in the config, but I basically have to tell it to ignore ALL of my libraries or else it always finds MY_Controller or one of the CRUD libraries.

So I thought about what Matchbox is doing and determined that in most cases it is not necessary to look back in the backtrace to determine what module to use.

If you think about it in 99% of cases it will only be looking at the current module, or the root for the files. On top of that it would only be looking in other modules for files if another module has been explicitly specified.
i.e.
Code:
$this->load->module_view('module', 'file_name');
After that call to load 'module' the view 'file_name' may need to find resources in the same module, but it has to be specified somewhere in code first to load something from this module.

The only issue I could come up with with this approach is that if I load something from an external module and it contains a resource with the same name as a resource in my module then the system could be confused about which one to load (the calling module would take precedence)

continued in next post....


Messages In This Thread
Matchbox callers and _remap - by El Forum - 02-18-2008, 05:51 PM
Matchbox callers and _remap - by El Forum - 02-18-2008, 05:56 PM
Matchbox callers and _remap - by El Forum - 02-19-2008, 07:20 AM
Matchbox callers and _remap - by El Forum - 03-08-2008, 09:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB