Php PluginManager::get无法获取或创建Controlador的实例

Php PluginManager::get无法获取或创建Controlador的实例,php,zend-framework,controller,zend-framework2,Php,Zend Framework,Controller,Zend Framework2,我试图创建一个插件控制器,如下所示: Application\src\Application\Controller\Plugin\Controlador.php namespace Application\Controller\Plugin; use Zend\Mvc\Controller\Plugin\AbstractPluginManager; use Biblioteca\Mvc\Db\TableGateway; class Controlador extends AbstractP

我试图创建一个插件控制器,如下所示:

Application\src\Application\Controller\Plugin\Controlador.php

namespace Application\Controller\Plugin;

use Zend\Mvc\Controller\Plugin\AbstractPluginManager;
use Biblioteca\Mvc\Db\TableGateway;

class Controlador extends AbstractPluginManager
{

   protected function getTable($table){

        $sm = $this->getServiceLocator();
        $dbAdapter = $sm->get('DbAdapter');
        $tableGateway = new TableGateway($dbAdapter, $table, new $table);
        $tableGateway->initialize();

        return $tableGateway;
    }

    protected function getService($service)
    {
        return $this->getServiceLocator()->get($service);
    }
}
namespace Application\Controller;</br>


use Zend\Mvc\Controller\AbstractActionController;

use Zend\View\Model\ViewModel;

use Biblioteca\ActionController;

class IndexController extends AbstractActionController{


    public function indexAction()
    {

        $controlador = $this->Controlador();

        return new ViewModel(array(
            'posts' => $controlador->getTable('Application\Model\Post')->fetchAll()->toArray()
        ));
    }
}
在我的module.config.php中,我放了以下内容:

'controllers' => array(
        'invokables' => array(
            'Application\Controller\Index' => 'Application\Controller\IndexController',

            'Controlador' => 'Application\Controller\Plugin\Controlador'
        ),
    ),
在我的indexController.php中,如下所示:

Application\src\Application\Controller\Plugin\Controlador.php

namespace Application\Controller\Plugin;

use Zend\Mvc\Controller\Plugin\AbstractPluginManager;
use Biblioteca\Mvc\Db\TableGateway;

class Controlador extends AbstractPluginManager
{

   protected function getTable($table){

        $sm = $this->getServiceLocator();
        $dbAdapter = $sm->get('DbAdapter');
        $tableGateway = new TableGateway($dbAdapter, $table, new $table);
        $tableGateway->initialize();

        return $tableGateway;
    }

    protected function getService($service)
    {
        return $this->getServiceLocator()->get($service);
    }
}
namespace Application\Controller;</br>


use Zend\Mvc\Controller\AbstractActionController;

use Zend\View\Model\ViewModel;

use Biblioteca\ActionController;

class IndexController extends AbstractActionController{


    public function indexAction()
    {

        $controlador = $this->Controlador();

        return new ViewModel(array(
            'posts' => $controlador->getTable('Application\Model\Post')->fetchAll()->toArray()
        ));
    }
}
名称空间应用程序\控制器
使用Zend\Mvc\Controller\AbstractActionController; 使用Zend\View\Model\ViewModel; 使用Biblioteca\ActionController; 类IndexController扩展AbstractActionController{ 公共函数索引() { $controlador=$this->controlador(); 返回新的ViewModel(数组( 'posts'=>$controlador->getTable('Application\Model\Post')->fetchAll()->toArray() )); } }
当我执行代码时,我得到一条消息:“Zend\Mvc\Controller\PluginManager::get无法获取或创建Controlador的实例”


有人可以帮我吗?

您正在负责创建控制器实例的controllerManager上注册插件。您需要在模块配置中使用“controller\u plugins”键定义它

return array(
    'controller_plugins' => array(
        'invokables' => array(
            'Controlador' => 'Application\Controller\Plugin\Controlador'
        )
    )
);
您还需要继承
AbstractPlugin
。现在您继承了
AbstractPluginManager
,您将使用它创建自己的插件管理器

use Zend\Mvc\Controller\Plugin\AbstractPlugin;

class Controlador extends AbstractPlugin
{

您正在负责创建控制器实例的controllerManager上注册插件。您需要在模块配置中使用“controller\u plugins”键定义它

return array(
    'controller_plugins' => array(
        'invokables' => array(
            'Controlador' => 'Application\Controller\Plugin\Controlador'
        )
    )
);
您还需要继承
AbstractPlugin
。现在您继承了
AbstractPluginManager
,您将使用它创建自己的插件管理器

use Zend\Mvc\Controller\Plugin\AbstractPlugin;

class Controlador extends AbstractPlugin
{