Jump to content

Setting new API via Wire


Recommended Posts


I believe I found a bug (https://processwire.com/api/ref/wire/wire/);

// Create a new API variable named 'widgets'
$this->wire('widgets', $widgets);

This didn't work but.

// Alternate syntax for the two above
$this->wire()->set('widgets', $widgets);

Did work.

This was in the `init.php` file using just `wire()` not `$this->wire()`. 

Anyone else had this issue? 

Link to comment
Share on other sites

There's a small but important difference between wire() and $anything->wire(). The first is the wire() function defined in Functions.php and documented here. The other is the Wire::wire() method you linked to. The first one just retrieves values but can't set them. So it's more of an inconsistency between those two than a bug.

  • Like 3
Link to comment
Share on other sites

I always use this approach:

$this->wire("siteSettings", $modules->get('SettingsFactory')->getSettings('settings'));

and it sets it just fine.

I put it in init.php

  • 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...