Laikmosh Posted December 11, 2018 Share Posted December 11, 2018 I've been using wire("pages") instead of $pages because sometimes the code is inside functions and the $pages var is not defined unless its included in the args, and i've foundin a post by Ryan that globals $var doesnt work at all in processwire, so for consistency i've been using wire('pages') anytime i need to find or get a page, but now im wondering if there might be any difference in performance from using one or the other Or maybe im just screwing everything up and there is another way to get global vars to work inside a function in processwire? Link to comment Share on other sites More sharing options...
Zeka Posted December 12, 2018 Share Posted December 12, 2018 @Laikmosh I'm not sure, but I think that there is no difference in performance between $pages, wire('pages) and pages(). There is also a third way to access API variables - functions API https://processwire.com/blog/posts/processwire-3.0.39-core-updates/#new-functions-api 2 1 Link to comment Share on other sites More sharing options...
Laikmosh Posted December 12, 2018 Author Share Posted December 12, 2018 wow, didnt know these things existed, thank you very much! one weird thing is that when i used it i got an error stating that "pages() is undefined", this function is supposed to work from 3.0.39+ and i have 3.0.98, ill chacke what might be the problem but for now i just made a function at the begining like this: function pages() { return wire('pages'); }; its a temporary solution while i find out the real problem but thanks for pointing me in the right direction! Link to comment Share on other sites More sharing options...
adrian Posted December 12, 2018 Share Posted December 12, 2018 5 hours ago, Laikmosh said: one weird thing is that when i used it i got an error stating that "pages() is undefined" Quoting from the blog post that @Zeka linked to: "At present, you have to tell ProcessWire you want to use the functions API by setting $config->useFunctionsAPI = true; in your /site/config.php file. Though after more testing, we may make it enabled by default in the future. If you don't have that $config property set to true, the functions are still available, but you have to prepend "wire" to them, i.e. the more verbose wirePages() rather than pages()." 3 Link to comment Share on other sites More sharing options...
bernhard Posted December 13, 2018 Share Posted December 13, 2018 On 12/12/2018 at 2:03 AM, Zeka said: There is also a third way to access API variables - functions API https://processwire.com/blog/posts/processwire-3.0.39-core-updates/#new-functions-api And a fourth: $this->wire->pages I prefer this version because you don't need to activate functionsapi (and the functions api should not be used in module development), it is multi instance proof and I get IntelliSense in my IDE Don't know which one is the best in terms of performance... 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now