Jump to content

Error: Call to undefined function wire()


Tom.
 Share

Recommended Posts

// create your hook function
function myHook(HookEvent $e) {
    echo "30 Minutes have passed!";
}
// add a hook to your function:
wire()->addHook('LazyCron::every30Minutes', null, 'myHook');

I'm trying to use above in my template file, however I'm getting the error:

Error: Call to undefined function wire() 

Any ideas why this isn't working?

Edit:

$wire->addHook seems to have got it. Is this still correct syntax? 

Link to comment
Share on other sites

Hello Tom.,

personally I never worked with hooks (although it is on my todo list). But I think the addHookMethod in the API reference is related to your question.

Available since version 3.0.16Added as an alias to addHook() for syntactic clarity, previous versions can use addHook() method with same arguments.

Regals, Andreas

Link to comment
Share on other sites

addHookMethod !== addHook, but wire() is namespaced as ProcessWire/wire() since 3.0.

I've used $wire->addHook, it seems to be working, however I was just wondering if this was incorrect and that I should use the namespaced wire(). 

Link to comment
Share on other sites

$wire and ProcessWire/wire() return the exact same object, but $wire is only available in template/bootstrap context. Depending on where you're trying to use wire() it might get compiled and should work as before. 

  • Like 3
Link to comment
Share on other sites

  • 1 year later...

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