Answer the question
In order to leave comments, you need to log in
ZF2 how to use the same set of functions in different controllers?
Hello! I am writing a Cats module in Zend Framework 2, which will allow editing and displaying information about cats.
I use Doctrine as an ORM.
Each cat has a relationship cat id->father id, cat id->mother id.
There is a method for building a pedigree: private function createPedigreeArray($config){}
There are also two methods
private function getFatherInfo(){}
private function getMotherInfo(){}
$objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
Answer the question
In order to leave comments, you need to log in
the same set of functions in different controllers?
Well, here you can do it differently.
Take out everything that is not action
in the service and connect it (as mentioned in the previous comment) through Dependency Injection.
You can, of course, write a trait and define the same set of functions there or expand AbstractActionController
it, but it seems to me that the service is better.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question