我试图创建一个插件控制器,如下所示:
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);
}
}
在我的 module.config.php 我把这个:
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => 'Application\Controller\IndexController',
'Controlador' => 'Application\Controller\Plugin\Controlador'
),
),
在我的 indexController.php 中是这样的:
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\PluginManager::get 无法为 Controlador 获取或创建实例”
有人可以帮助我吗?