ZF2 -- Class 'Action\Model\Action' 未在 'pathto\module\Action\Module.php' 中找到

ZF2 -- Class 'Action\Model\Action' not found in 'pathto\module\Action\Module.php'

我遵循了 ZF2 网站 (http://framework.zend.com/manual/current/en/user-guide/database-and-models.html) 上入门教程的每一步。

我已经在该网站(当然还有 google)上搜索了可能的解决方案。我不会说谎,除了所有给出的解决方案似乎都不起作用之外,有成千上万的问题看起来像这些问题。

这些是错误代码:(对格式感到抱歉) ( !) 致命错误:Class 'Action\Model\ActionTable' 未在第 46 行的 C:\wamp\www\zf2\module\Action\Module.php 中找到


Module.php(低于 module/Action)

<?php

/**
 * ZF2 uses ModuleManager to load and configure a module. To do that, it will look up for this class in the root of the module directory. 
 */

namespace Action;
use Action\Model\ActionTable;
use Action\Model\Action;


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

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;


/**
 * Class Module is expected by ZF2.
 */
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(
                 'Action\Model\ActionTable' =>  function($sm) {
                     $tableGateway = $sm->get('ActionTableGateway');
                     $table = new ActionTable($tableGateway);
                     return $table;
                 },
                 'ActionTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new Action());
                     return new TableGateway('action', $dbAdapter, null, $resultSetPrototype);
                 },
             ),
         );
    }


}
?>

ActionTable.php(在 module/Action/src/Action/Model 下)

<?php
namespace Action\Model;

use Zend\Db\TableGateway\TableGateway;

class AlbumTable
{
    protected $tableGateway;

    /**
     * TableGateway is an object that represents a table in a database. 
     */
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
    }

    /**
     * fetchAll function
     * retrieves all rows from the database
     * @return ResultSet containing all rows of the database.
     */
    public function fetchAll()
     {
         $resultSet = $this->tableGateway->select();
         return $resultSet;
     }

    /**
     * getAction function
     * retrieves a single row from the database using the id
     * @param $id (int)
     * @return $row of error in exception
     */
     public function getAction($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;
     }

    /**
     * saveAction function
     * Creates a new row in the database or updates a row that already exists
     * @param Action
     * print Exception if error
     */
     public function saveAction(Action $action)
     {
         $data = array(
            'Num_action'=> $action-> $act_num,
            'libelle_action'=> $action-> $act_label,

         );

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


    /**
     * deleteAction function
     * removes a row completely
     * @param $id
     */
     public function deleteAction($id)
     {
         $this->tableGateway->delete(array('id' => (int) $id));
     }

}
?>

体系结构很好,文件在他们所说的地方,我试过在 ActionTable($tableGateway) 之前添加 \Action\Model\... 似乎没有任何效果。

大家有什么想法吗??

非常感谢你提供任何线索,任何线索,你可以给我。

在第 6 行的 ActionTable.php 中:

class AlbumTable

大概应该是

class ActionTable

其他一切看起来都不错。