zf2 Creation of simple service and access it through viewhelper

后端 未结 2 878
轮回少年
轮回少年 2020-12-08 12:26

I am trying to create a simple service in zf2 which I can access using in viewhelper

Step1. I have craeted a class in src/Application/Service/Servic

2条回答
  •  被撕碎了的回忆
    2020-12-08 12:36

    change the line $this->sm->getServiceLocator()->get('Application\Service\Service1'); in below method

    class Abc extends AbstractHelper 
    {
       protected $sm;
    
       public function test()
        {
            $this->sm->getServiceLocator()->get('Application\Service\Service1');
        }
        public function __construct($sm) {
            $this->sm = $sm;
    
        }
    }
    

提交回复
热议问题