[SOLVED] Correctly override Account functions


Note: I’ve figured this out while writing it up (isn’t that often the way?), but will post anyway since it caused me a lot of head scratching. A total beginner’s error!

I’ve created a simple sprinkle called extend-account. I need to add a couple of things to the user-facing account profile page. I’m able to override the templates/locale file/config just fine, but I simply cannot get UF to read in my Controller file.

I have specified it in the autoload: "autoload": { "psr-4": { "UserFrosting\\Sprinkle\\ExtendAccount\\": "src/" } }

I’ve checked in app/vendor/composer that my src directory is being loaded: 'UserFrosting\\Sprinkle\\ExtendAccount\\' => array($baseDir . '/app/sprinkles/extend-account/src'),

I have an Account.php file in the root of src with the namespace namespace UserFrosting\Sprinkle\ExtendAccount;, and then a subfolder with the controller.

I imagine I’m making a simple daft error …
YES I was - I had defined the locale/templates etc and these were coming through, so I thought my work was done. But I hadn’t defined the routes to be overridden - hence UF was reading in the routes from the main Account sprinkle and was never using my source files, even though they had been loaded in and were available.

Hope this helps someone.


yep! There is no way for UF to know that UserFrosting/Sprinkle/Account/Controller/AccountController is related in any way to your UserFrosting/Sprinkle/ExtendAccount/Controller/AccountController class.

This is the same reason we have the dynamic class mapper for models and other types of classes that need to be extended/overridden in your Sprinkle. Unfortunately, using this approach with controller classes would be very difficult, and it is far simpler to just override your route definitions (as you have done).