0

Zend Skeleton App を使用した最初のチュートリアルの何が問題なのかを理解しようとしています。Zend Studio 10 + ZendServer と Zf2.2 を使用しています。スケルトン アプリを動作させることができましたが、クラスが見つからないという問題が発生しました (以下のエラーを参照)。さまざまなアプローチを試しましたが、結果は同じです: it's not working . ここに私のファイルがあります。

私のエラー:

致命的なエラー: クラス 'Album\Model\AlbumTable' が C:\Program Files\Zend\Apache2\htdocs\zf2album\module\Album\Module.php の 55 行目に見つかりません

アルバム/Module.php

名前空間アルバム;

アルバム\モデル\アルバムを使用します。

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 extends AbstractActionController { 保護された $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

名前空間アルバム\モデル;

Zend\Db\TableGateway\TableGateway を使用します。

class AlbumTable { 保護された $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));
} }
4

1 に答える 1