Скелет приложения Zend. Класс «Album\Model\AlbumTable» не найден.Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Скелет приложения Zend. Класс «Album\Model\AlbumTable» не найден.

Сообщение Anonymous »

Я пытаюсь понять, что не так с моим первым уроком с использованием приложения Zend Skeleton. Я использую Zend Studio 10 + ZendServer и Zf2.2; удалось заставить скелетное приложение работать, и теперь он застрял в проблеме с отсутствующим классом (см. ошибку ниже). Я пробовал разные подходы, но результат тот же: это не работает. Вот мои файлы, буду благодарен за любую помощь.

Моя ошибка:


Неустранимая ошибка: класс «Album\Model\AlbumTable» не найден в C:\Program
Files\Zend\Apache2\htdocs\zf2album\module\Album\Module.php в строке 55


Album/Module.php


Альбом пространства имен;

используйте Album\Model\Album;

используйте Album\Model\AlbumTable;

используйте Zend\Db\TableGateway\TableGateway;

используйте Zend\ModuleManager\Feature\ServiceProviderInterface;

Модуль класса реализует ServiceProviderInterface {

Код: Выделить всё

public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
// if we're in a namespace deeper than one level we need to fix the \ in the path
__NAMESPACE__ => __DIR__ . '/src/' . str_replace('\\', '/' , __NAMESPACE__),
),
),
);
}

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

// Add this method:
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


пространство имен Альбом\Контроллер;

используйте Zend\Mvc\Controller\AbstractActionController; используйте
Zend\View\Model\ViewModel;

class AlbumController расширяет 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 fooAction()
{
// This shows the :controller and :action parameters in default route
// are working when you browse to /album/album/foo
return array();
}

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

AlbumModel.php


Пространство имен Альбом \Model;

используйте Zend\Db\TableGateway\TableGateway;

класс AlbumTable {
protected $tableGateway;

Код: Выделить всё

public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
}

public function fetchAll()
{
$resultSet = $this->tableGateway->select();
return $resultSet;
}

public function getAlbum($id)
{
$id  = (int) $id;
$rowset = $this->tableGateway->select(array('id' => $id));
$row = $rowset->current();
if (!$row) {
throw new \Exception("Could not find row $id");
}
return $row;
}

public function saveAlbum(Album $album)
{
$data = array(
'artist' => $album->artist,
'title'  => $album->title,
);

$id = (int)$album->id;
if ($id == 0) {
$this->tableGateway->insert($data);
} else {
if ($this->getAlbum($id)) {
$this->tableGateway->update($data, array('id' => $id));
} else {
throw new \Exception('Form id does not exist');
}
}
}

public function deleteAlbum($id)
{
$this->tableGateway->delete(array('id' => $id));
} }


Подробнее здесь: https://stackoverflow.com/questions/167 ... -not-found
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»