0

I am working on a project to migrate from ZF2 to ZF3. I am facing a problem and try to solve by googled but no luck.

$this->dbAdapter = $this->getServiceLocator()->get('db');
$DBQueryObj = new DBQuery($this->dbAdapter, 'tbl_user');  // custom function

I need a similar code in ZF3 for this line so that I can pass adapter instance in my custom function.

$this->dbAdapter = $this->getServiceLocator()->get('db');

Can anyone point me how to achieve this in ZF3?

Thank you

Katty
  • 489
  • 6
  • 28
  • 2
    ServiceLocatorAwareInterface is deprecated as of ZF3 this means the controller plugin manager does not inject servicelocator instance into the created controllers anymore. See this SO answer for a more detailed insights: https://stackoverflow.com/questions/36969109/how-can-i-set-up-lazy-loading-with-zf3-no-servicelocator-pattern-from-anywhere – edigu Apr 05 '18 at 11:42

1 Answers1

1

service names are case sensitive

fore example : zf2 there was "viewhelpermanager" as well as "ViewHelperManager", now in Zf3, only "ViewHelperManager" available.

but in Zf3 add bellow line in Module.php.

public function getServiceConfig()
    {
        return array(
            'aliases' => array(
                'viewhelpermanager' =>'ViewHelperManager'
             )
        );
    }

If getServiceConfig() exists then add

'aliases' => array(
                    'viewhelpermanager' =>'ViewHelperManager'
                 )

for more infomation and details, please see migration guide Zf2 to Zf3

Sunny Kalariya
  • 336
  • 2
  • 9