Message of the day:
Welcome. Latest release: https://www.silverstripe.org/download Community Forum: https://forum.silverstripe.org Features: https://forum.silverstripe.org/c/feature-ideas Archive: https://slackarchive.silverstripe.org
If you have any SilverStripe related questions, please supply the version of Framework you're using.
Did you flush? 🚽 =
Archive temporarily at https://archive.codingplayground.nl (redirect)
@Admonish Helpers need not be in their own class (entirely full of helpers) though. E.g. if generateUniqueID is specific to ... Member - Member::generateUniqueID() - and does not have context outside member, then leaving it in the Member class is fine. If it's static and public it can still be called from anywhere. If it's Unique globally (throughout the entire system) and not tied to any particular class, then you'd think about putting it somewhere else that makes sense in such a global context E.g. perhaps on a boot class called "App", or into a helper class as you describe.
ClassInfo is a helper class in Framework you could look at :)
NVM I got it sorted
- <?php //...
- public static function generateUniqueID($uniqueID)
- // Get the products ID and ID length and store them
I bring this up now because I am currently working with a method called generateUniqueID() that I had created awhile back inside one of my DataObjects. Now I'm wondering if I should strip it out into its own helper class.
I have a tendancy to try to make something static if it can be made static. But now I'm thinking that I should only make it static if its somethig pretty generic and reusable E.g. a Math helper classes for generic math formulas
So my question is what is the best way to make a helper class in silverstripe and (more importantly) when should I remove a method from a controller or DataObject and place it in a helper class?
Hey guys n gals. So Lately I have been researching into best practices and design patterns trying to up my php game and one of the things that became glaringly obvious to me way my misuse of static methods up to this point. From what I understand now I should only be using static methods in helper classes so that I don't cause unit testing problems (among other things).
I usually just work on my vm via samba
I don't like exposing Samba on a production machine