4

can anyone suggest me how can I use a custom class for writing all helper methods so that the app doesn't repeat same code again and again in different controllers? How can I share codes between controllers? Thank you

Hkm Sadek
  • 2,348
  • 5
  • 26
  • 62

1 Answers1

6

Ok I solved it. In case someone else is trying to solve it, here is how I solved

In app folder I created a folder named Common. Inside this folder I have a index.js. (App/Common/index.js) in this file I have

'use strict';

module.exports = class Help {
  display() {
    console.log('is it ok?')
  }
}

Now in my controllers I need to use it like this

var Help = use('App/Common')

In order to call the display method I need to call just like a normal OOP call

var obj = new Help();
obj.display();

That's it.

Hkm Sadek
  • 2,348
  • 5
  • 26
  • 62