cryostar Posted June 21, 2021 Posted June 21, 2021 I created a "/utils/helpers.php" file to store all reusable functions and "include()" it on "ready.php" which works fine and all, but I cannot access the ProcessWire API variables. What's the best practices for these kinds of functions? ?
Jonathan Lahijani Posted June 21, 2021 Posted June 21, 2021 I think namespacing your file with the ProcessWire namespace should fix your issue. 2
cryostar Posted June 26, 2021 Author Posted June 26, 2021 On 6/22/2021 at 2:40 AM, Jonathan Lahijani said: I think namespacing your file with the ProcessWire namespace should fix your issue. I did what you said but seems like it didn’t work. Do I have to put it in a class for it to work? Currently it’s all a list of functions so I’m not sure if namespacing works on these kinds.
Macrura Posted June 26, 2021 Posted June 26, 2021 depends on what you are doing – if you mean that you can't access the api vars inside a function, that's one issue; usually i put all of the helper functions inside /site/templates/helpers/ and then include them in the template folder _init.php file and that definitely works. If you need to use those in the admin then that's also a different thing, but in short you should be able to do some quick tests like write a simple function in the ready.php file and see how it works.. then move it to your include file and see if it still works... 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now