A plugin by the name "getServiceLocator" was not found in the plugin manager Zend \ Mvc \ Controller \ PluginManager

1

I recently started learning Zend Framework2 with AngularJS through a course of the School of Net. Given the course year, if I'm not mistaken it's 2013, some things have changed in both frameworks. So I encountered a problem using the following code snippet to test the connection to the database and list the records using Doctrine 2:

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController {
    public function indexAction() {
        $em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
        $repo = $em->getRepository('Entity\Categoria');

        $categorias = $repo->findAll();

        return new ViewModel(['categories'=>$categorias]);
    }
}

When I run the application, it returns the following error:

  

A plugin by the name "getServiceLocator" was not found in the Zend \ Mvc \ Controller \ PluginManager plugin manager

In addition, additional information:

  

Zend \ ServiceManager \ Exception \ ServiceNotFoundException

And the file where the message appears to come from:

  

C: \ xampp \ htdocs \ ZF2 \ vendor \ zendframework \ zend-servicemanager \ src \ AbstractPluginManager.php course: 133

As far as I know, the problem stems from the fact that the getServiceLocator() method was removed from the newer versions of the Zend Framework 2. However, I have no idea how to resolve so I can continue my testing and pass on the course. Can someone give me a light?

    
asked by anonymous 01.09.2016 / 20:09

0 answers