0

I'm a beginner in MVC. I'm creating a logic to convert text to voice by MVC pattern. I have speakerController, speakerView, speakerModel. The controller transfers text from the model to the view to be spoken. Also, on press the same button, the pronunciation stops.

But I also have another controller that is responsible for the page logic. If the user presses the back button, then the pronunciation should stop. What is the best way to implement this? Will it be correct to call a speakerController from another controller or connections between controllers are not allowed and need to be done in another way?
Thank you

1 Answers1

0

There is no problem at all calling a method from the speakerController inside your pageController.

As I understand it from what you described, you want speakerController to hold the real processing logic. In a proper implementation, there should be a service called something like speakerService which has at least these 2 methods:

function play() {
  // .. method logic
}

function stop() {
  // .. method logic
}

This service could then be called by any controller (including speakerController).

Please bear in mind that this is not an obligation, you could just as well have all the service logic held in speakerController which will be acting just like speakerService

In your pageController you'll have a method which fires after intercepting the event of the back button click like so:

function onClickBackBtn($event) {
  // ..  rest of the logic
  speakerService.stop(); // <-- call to the external speakerService method
}
wiwi
  • 270
  • 2
  • 9