ZF2 - Class' Action \ Model \ Action'找不到路径\ module \ Action \ Module.php'

时间:2015-08-14 12:26:29

标签: php zend-framework

我按照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(在模块/行动下)

<?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(在模块/ 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 \ ... 似乎没什么用。

任何人都有任何想法??

非常感谢你的任何线索,任何领导,你都可以给我。

1 个答案:

答案 0 :(得分:1)

第6行的ActionTable.php

class AlbumTable

大概应该是

class ActionTable

其他一切看起来都不错。