Jump to content

Recommended Posts

Posted

I have a module

class MyModule extends WireData implements Module, ConfigurableModule {

and I wonder why I could not use:

$this->pages->get(123);

I always have to do:

Wire::getFuel('pages')->get(123);

Does anyone knows what's going wrong?

Posted

Where exactly are you calling this?

If you're inside a static method, you don't have access to the "$this" object, you can use

$page = wire('pages')->get(123);
  • Like 1
Posted

No, it's not in a static function, it's in a public function.

$page = wire('pages')->get(123);

Doesn't also work :(

EDIT:

"wire('pages')->...." does work!

Posted

The only reason why $this->pages->get(123); wouldn't work in a class that extends Wire or WireData (as yours does) is if you added your own implementation for a get() or __get() method. That's because something like $this->pages (or $this->any API var) gets routed through both get() and __get() in Wire/WireData.

The nice thing about wire('pages') or wire('any API var') is that it works anywhere. Also wanted to mention that wire('pages'); is the new Wire::getFuel('pages'). They are both equivalent, but the getFuel() one just looks ugly. You'll see it used in some older modules and core code, but there's no reason to use it anymore. (though also no real reason to change it if you already are, as it's not going to be deprecated either).

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