Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Config "magic": search within the module of the active request first
  • Hello, I'm having an issue with the Fuel::find_file() class wanting to search within the module of the active request first.
    The "problem" is that I already loaded the module by hand first and I don't want it to have priority.
    The path of the module is already included in Fuel::$_paths, in the correct priority order for me. These are the paths before the module from the active request is added:
    Array
    (
        [0] => /data/www/website/app/
        [1] => /data/www/website/modules/novius/
        [2] => /data/www/website/packages/orm/
        [3] => /data/www/website/app/fuel/
    )
    

    novius is the module I was talking about. ... and after the module from the active request is added:
    Array
    (
        [0] => /data/www/website/modules/novius/
        [1] => /data/www/website/app/
        [2] => /data/www/website/modules/novius/
        [3] => /data/www/website/packages/orm/
        [4] => /data/www/website/app/fuel/
    )
    

    What can I do apart from extending the find_file() function?
  • Use it the way it was designed to work? When called from a module via a request, the module is always searched first, allowing you to override global files. In general, when you have a config/view/other file with the same name in both the module and the app, you would want the module file to be loaded. I've updated Fuel::add_path() to not add a path if it is already present, which would give you your desired behaviour.
  • This will not solvve the problem, as the merge is here: https://github.com/fuel/core/blob/develop/classes/fuel.php#L269 I created a global controller which handle every request and do some HMVC. I could also solve my problem by having 2 app folders used in the same time (but that's not an option I presume).
  • @WanWizard Does that mean that users always_load-ing a module don't get it prefixed anymore when it's an active request? I think by far most users would prefer it to be prefixed.
    Also, when using the $force param it gets added a second time. Why not delete the first usage when that happens? I don't think there's a use to searching a path possibly twice?
  • In fact I pretty much always know where to search the config file. I guess my best shot is to write my own config class to fetch the correct one. Consider this as solved. ;-)
  • Please open an issue on the GitHub issue tracker (for Core). It is acting as expected, the active requested module will always be first in the load path...this will not change. However, it should not be in there twice. If it is already loaded when the active module is loaded then it should be moved to the top of the stack...not simply added to the top and left in place. Dan
  • Currently the search order is: first active request paths, then global search paths. This behaviour doesn't change. You can manually add search paths to the global list using Fuel::add_path(). You can manually add search paths to the request using Request::active()->add_path(). @Julian Esperat, if you want the APPPATH to be searched first, add it to the request search path using the prefix switch, so it will be inserted before any globally defined paths, and before local request search paths. @Jelmer, No, that doesn't mean that. It only means that if you have manually added a module path to the global search paths using Fuel::add_path(). Modules are not added to the global path, not even on always_load. I'll revert the commit, as you can achieve the required behaviour using the existing add_path() methods.
  • It's only a local variable used during the time find_file() is executing which is affected. Not a big deal, or is it?
  • @Julian Esperat, if you want the APPPATH to be searched first, add it to the request search path using the prefix switch, so it will be inserted before any globally defined paths, and before local request search paths.

    You lost me, what is the "prefix switch"? Where should I add something? ^^
  • RTFM ;) See http://fuelphp.com/docs/classes/request.html#method_add_path. The $prefix parameter determines if the path you're adding will be appended (default) or prepended (or prefixed)... So in your module controller you can add
    \Request::active->add_path(APPPATH, true);
    

    to make sure the application path is at the top of the search list...
  • Ok, I see now. Thank you!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion