Jump to content

Where to place custom helpers/utilities?


cryostar
 Share

Recommended Posts

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? 😲

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...