Jump to content

what does setfuel() do and when would i use it?


benbyf
 Share

Recommended Posts

Wire::setFuel() is a deprecated method, so don't bother using it. But the purpose of it was to set an API variable. The recommend way to set an API variable now is using the $this->wire() method (available on any Wire derived object). 

// Set a 'hello' API variable
$this->wire('hello', 'Hello World!');

// If outside an object (like in template file) you might do this instead
$wire->wire('hello', 'Hello World!');

// If you want to lock it (prevent changes) specify TRUE as last argument
$this->wire('hello', 'Hello World!', true);

Once an API variable is set, it works the same as any other API variable in PW. It can be retrieved like this: 

echo $this->wire('hello'); // in object
echo $this->hello; // in object
echo wire('hello'); // anywhere
echo $wire->wire('hello'); // in template file
echo $wire->hello; // in template file
echo $hello; // in template file

All of the above do the same thing. The first two are what you might do from within a Wire derived object or module. And the rest are what you might do from a template file or related (like init.php or ready.php). The last (shortest) example would require that the 'hello' API variable had been set before the file that it's in (like a template file) had started rendering. 

See the wire() method documentation for more. 

  • Like 7
Link to comment
Share on other sites

Amazing thanks Ryan! Think the new pattern makes more sense and doesn't have a confusing name.

Given the above, would it be advisable to state a

$this->wire('yourModule',  functionName); 

to be used to echo module markup in templates (e.g. instagram html code or similar), instead of the curent

$module = $modules->getModule("moduleName");

Thanks!

Link to comment
Share on other sites

Some autoload modules establish API variables, like ProCache ($procache) and FormBuilder ($forms). But the wire() method really doesn't have anything to do with modules at all (other than that you can retrieve the $modules API var from it). So continue using $modules->get() to retrieve your modules, and avoid stuffing modules into API vars unless it's something the module itself intends. However, anytime you find the ability to establish your own API vars useful, there's certainly no harm in using it. Just keep in mind that var will remain in scope for the entire request. 

  • Like 2
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...