尚未找到Zend骨架应用程序类'Album \ Model \ AlbumTable'

时间:2013-05-23 14:32:45

标签: zend-framework frameworks

我试图弄清楚使用Zend Skeleton App的第一个教程有什么问题。我使用的是Zend Studio 10 + ZendServer和Zf2.2;设法使骨架应用程序正常工作,现在陷入了缺失的类问题(请参阅下面的错误)。我尝试了各种方法,但结果是一样的:它不能正常工作。这是我的文件,任何帮助将不胜感激。

我的错误:

  

致命错误:Class' Album \ Model \ AlbumTable'在C:\ Program中找不到   第55行的Files \ Zend \ Apache2 \ htdocs \ zf2album \ module \ Album \ Module.php

专辑/ Module.php

  

namespace Album;

     

使用相册\模型\相册;

     

使用Album \ Model \ AlbumTable;

     

使用Zend \ Db \ TableGateway \ TableGateway;

     

使用Zend \ ModuleManager \ Feature \ ServiceProviderInterface;

     

class Module实现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

  

namespace Album \ Controller;

     

使用Zend \ Mvc \ Controller \ AbstractActionController;使用   的Zend \视图\模型\视图模型;

     

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

  

namespace Album \ Model;

     

使用Zend \ Db \ TableGateway \ TableGateway;

     

class 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));
} }

1 个答案:

答案 0 :(得分:1)

假设这不是您问题中的拼写错误,则类AlbumTable的文件名应为AlbumTable.php,而不是AlbumModel.php