Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Aliasing classes to global from packages and modules
  • I think what I want to do here is relatively straightforward, but I can't seem to figure it out. I'm building my auth system as a package and it includes two models, Model_User and Model_TempUser. I want to be able to load these models in and use them within the package, but allow them to be overwritten by the app in a user module as each app will have different requirements for what the User_Model actually looks like. I'd like to be able to use the models within a global namespace similar to \Model_User within my application.
    So what I'd have is:
    packages>infusedauth>classes>model>user.php: class Model_User extends \Orm\Model
    app>modules>user>classes>model>user.php: class Model_User extends \InfusedAuth\Model_User I want the package to use the Model_User from the user module if it exists, and fallback on the InfusedAuth\User_Model in the package if extending the model is not necessary. Some things I've tried:
    - always loading the user module via config
    - adding the user module user model classes in app bootstrap and then alias_to_namespace global
    - adding classes with autoload in the InfusedAuth package with key 'Model_User' instead of 'InfusedAuth\Model_User'
    - And various combinations of the above.
    - I use \Model_User inside the package Some of the problems I get:
    - Always uses InfusedAuth\Model_User and never the User\Model_User
    - User\Model_User attempts to be used but then can't find InfusedAuth\Model_User
    - Can't find \Model_User at all
  • FYI, I seem to be able to accomplish this with packages because there is the bootstrap file. Is there a similar mechanism of bootstrap for when modules are loaded?
  • There is no easy solution, and you definately want to avoid messing to much with the global namespace. You could make it variable, and part of the Auth setup, and use the default from the package if not set:
    Yourauth::set_model('\\Module\\Model_User');
    

    ( or make it configurable through a config file )

Howdy, Stranger!

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

In this Discussion