gpt4 book ai didi

php - Zend2 fatal error : Class 'Album\ResultSet' not found

转载 作者:可可西里 更新时间:2023-10-31 23:57:07 26 4
gpt4 key购买 nike

我是 Zend2 的新手,我正在关注 Zend 上的相册教程。我收到以下错误:

Fatal error: Class 'Album\ResultSet' not found in C:\websites\Zend2\module\Album\Module.php on line 51

我找不到问题所在,我做错了什么?我错过了一些代码吗?还是我错过了教程中的一些规则?

Module.php
<?php
namespace Album;

use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;

class Module
{
public function onBootstrap(MvcEvent $e)
{
$e->getApplication()->getServiceManager()->get('translator');
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}

public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}

public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getServiceConfig()
{
return array(
'factories' => array(
'Album\Model\AlbumTable' => function($sm) {
$tableGateway = $sm->get('AlbumTableGateway');
$table = new AlbumTable($tableGateway);
return $table;
},
'AlbumTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Album());
return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
},
),
);
}

}


AlbumController.php
<?php
namespace Album\Controller;

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

class AlbumController extends AbstractActionController
{
protected $albumTable;
public function indexAction()
{
return new ViewModel(array(
'albums' => $this->getAlbumTable()->fetchAll(),
));
}

public function addAction()
{
}

public function editAction()
{
}

public function deleteAction()
{
}

public function getAlbumTable()
{
if (!$this->albumTable) {
$sm = $this->getServiceLocator();
$this->albumTable = $sm->get('Album\Model\AlbumTable');
}
return $this->albumTable;
}
}

最佳答案

您还没有在 module.php 文件中添加 ResultSet 类。将其添加到那里。

<?php
namespace Album;

use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Album\Model\Album;
use Album\Model\AlbumTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;

必须在文件中添加类才能使用它。

关于php - Zend2 fatal error : Class 'Album\ResultSet' not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16097498/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com