Jump to content

difference between $this->wire('xyz') and wire('xyz')


bernhard
 Share

Recommended Posts

if you want to get access to eg $pages in modules you have to do something like $pages = wire('pages');

sometimes i see people using $this->wire('pages') like here for example: https://processwire.com/talk/topic/11939-make-dashboard-plugin-page-the-default-admin-page/?p=111017

is there any difference in those two methods?

i also saw $this->user->name and i was not sure if that would work inside a module because i thought it should be wire('user')->name

thank you in advance :)

Link to comment
Share on other sites

In some cases it doesn't matter, and in some cases it does :)

It depends on the scope and class context as to whether $this->user->name will work or not, but seems to have been common practice in various modules.

With PW 3.x ramping up I would suggest reading this: https://processwire.com/blog/posts/processwire-2.6.21-upgrades-comments-more-on-pw-3.x/#more-updates-on-processwire-3.0 - scroll down a little to the "Multi-instance with 3rd party modules and PW 3.x" section where it explains what works where.

Actually this is a good reminder for me to update my modules to use $this->wire()

  • Like 6
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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