2

I'm tired of typing $this->countModules('...'). Is there a way to make alias to that function, something similar as in JavaScript when I just do var alias = myFunction?

I have tried assigning $this to a global variable, and than use wrapper function and I have tried use $this->countModules as m but none of that works.

Thanks!

6

There is simply no need to do this. As @Bakual has already said, your approach is bad practice.

For starters, you are wrapping a function within a function unnecessarily when it's not required. You are then returning JFactory::getDocument()->countModules(...), meaning you are calling the JFactory class, then calling JDocument which has to check if it already exists before creating it, and then the countModules() function. Overall you are slowing down the process.

Keep things simple by sticking to $this->countModules()

2

I have figured it out, after some more tinkering:

//Shorthand for countModules function
function m($arguments) {
    return JFactory::getDocument()->countModules($arguments);
}
  • 2
    You can do that, but it's certainly not good practice. – Bakual Jul 30 '14 at 12:41
  • @Bakual why is that so? – Jinx Jul 30 '14 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.