0

我是 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()

我的程序结构是这样的:

在此处输入图像描述

在AkulubalaModule.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', 'host'=> 'localhost', 'options' => 数组('buffer_results' => true ), ), 'service_manager' => array( 'factories' => array( 'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\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()
{

}
}
4

0 回答 0