R
R
RJs452014-08-29 09:29:59
Zend Framework
RJs45, 2014-08-29 09:29:59

How to use non-ZF2 code in ZF2?

There is a ready-made function for generating XML, which uses a third-party library.
It was required to implement it in the finished site on ZF2.
I could copy-paste into the controller in some of the Action code, but how to connect this third-party library?
I am not familiar with ZF in principle, but I always wanted to know it - this was an opportunity.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-08-29
@RJs45

composer for dependencies. And copy-pasting something into controllers is not good, controllers should be thin and stupid and should not really be able to do anything. If the controller needs to do something, then usually it calls the service and asks the service to do what needs to be done.
Service is just class. In the context of your question, this is a class to which an instance of the library on which it depends is passed to the constructor. All this is resolved through Dependency Injection.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question