How to use dependency injection in Zend Framework?

前端 未结 5 816
攒了一身酷
攒了一身酷 2021-02-02 14:52

Currently I am trying to learn the Zend Framework and therefore I bought the book \"Zend Framework in Action\".

In chapter 3, a basic model and controller is introduced

5条回答
  •  Happy的楠姐
    2021-02-02 15:26

    I'm currently working on the same question, and after deep research I've decide to use Symfony Dependency Injection component. You can get good info from official website http://symfony.com/doc/current/book/service_container.html.

    I've build custom getContainer() method in bootstrap, which resturns now service container, and it simply can be used in controllers like

    public function init()
    {
        $sc = $this->getInvokeArg('bootstrap')->getContainer();
        $this->placesService = $sc->get('PlacesService');
    }
    

    Here you can find how to do that http://blog.starreveld.com/2009/11/using-symfony-di-container-with.html. But I changed ContainerFactory, because of using Symfony2 component, instead of first version.

提交回复
热议问题