我是Zf2的新手,当我不想添加新模块开始时我遇到了这个错误:
File:
D:\wamp\www\akulubala_project\system\Zend\ServiceManager\ServiceManager.php:455
Message:
Zend\Mvc\Controller\PluginManager::get was unable to fetch or create an instance for getakulubalaTablekulubalaTable
Stack trace:
#0 D:\wamp\www\akulubala_project\system\Zend\ServiceManager\AbstractPluginManager.php(103): Zend\ServiceManager\ServiceManager->get('getakulubalaTab...', true)
#1 D:\wamp\www\akulubala_project\system\Zend\Mvc\Controller\PluginManager.php(98): Zend\ServiceManager\AbstractPluginManager->get('getakulubalaTab...', NULL, true)
#2 D:\wamp\www\akulubala_project\system\Zend\Mvc\Controller\AbstractController.php(285): Zend\Mvc\Controller\PluginManager->get('getakulubalaTab...', NULL)
#3 D:\wamp\www\akulubala_project\system\Zend\Mvc\Controller\AbstractController.php(300): Zend\Mvc\Controller\AbstractController->plugin('getakulubalaTab...')
#4 D:\wamp\www\akulubala_project\module\Akulubala\src\Akulubala\Controller\IndexController.php(14): Zend\Mvc\Controller\AbstractController->__call('getakulubalaTab...', Array)
#5 D:\wamp\www\akulubala_project\module\Akulubala\src\Akulubala\Controller\IndexController.php(14): Akulubala\Controller\IndexController->getakulubalaTablekulubalaTable()
我的程序结构是这样的:
Akulubala下的
和Module.php
是:
namespace Akulubala;
use Akulubala\Module\AkulubalaTable;
use Akulubala\Module\Akulubala;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
class Module
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(__DIR__.'/autoload_classmap.php'),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array( __NAMESPACE__ => __DIR__ .'/src/'.__NAMESPACE__,),
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getServiceConfig()
{
return array(
'factories' => array(
'Akulubala\Model\AkulubalaTable' => function($sm) {
$tableGateway = $sm->get('AkulubalaTableGateway');
$table = new AkulubalaTable($tableGateway);
return $table;
},
'AkulubalaTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Akulubala());
return new TableGateway('Akulubala', $dbAdapter, null, $resultSetPrototype);
},
),
);
}
}
config/autoload/global.php
是
返回数组(
'db'=>阵列(
'driver'=> 'mysqli的',
'DBNAME'=> 'akulubala',
'主机'=> 'localhost' 的,
'options'=>阵列(
'buffer_results'=>真正
)
)
'service_manager'=>阵列(
'工厂'=>阵列(
'Zend \ Db \ Adapter \ Adapter'=> '的Zend \ DB \适配器\ AdapterServiceFactory',
)
)
);
这是我的控制器文件:
namespace Akulubala\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
{
protected $akulubalaTable;
public function indexAction()
{
return new ViewModel(array('akulubala' => $this->getakulubalaTable()->fetchAll()));
}
public function getakulubalaTable()
{
if (!$this->akulubalaTable) {
$sm = $this->getServiceLocator();
$this->akulubalaTable = $sm->get('Akulubala\Module\AkulubalaTable');
}
return $this->akulubalaTable;
}
public function editAction()
{
}
public function deleteAction()
{
}
public function addAction()
{
}
}