[PHP][Zend] Fatal error: Uncaught Error: Class 'Film\Model\Film'

[PHP][Zend] Fatal error: Uncaught Error: Class 'Film\Model\Film'

我打算学习 Zend Framework,当我尝试创建一个必须从数据库读取一些信息的新模块时,我遇到了这个错误:

Fatal error: 
Uncaught Error: Class 'Film\Model\Film' not found in /Applications/XAMPP/xamppfiles/htdocs/provaVicky/provaVicky/module/Film/Module.php:41 Stack trace: #0 [internal function]: Film\Module->Film\{closure}(Object(Zend\ServiceManager\ServiceManager), 'filmtablegatewa...', 'FilmTableGatewa...') 
#1 /Applications/XAMPP/xamppfiles/htdocs/provaVicky/provaVicky/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(939): call_user_func(Object(Closure), Object(Zend\ServiceManager\ServiceManager), 'filmtablegatewa...', 'FilmTableGatewa...') 
#2 /Applications/XAMPP/xamppfiles/htdocs/provaVicky/provaVicky/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(1099): Zend\ServiceManager\ServiceManager->createServiceViaCallback(Object(Closure), 'filmtablegatewa...', 'FilmTableGatewa...') 
#3 /Applications/XAMPP/xamppfiles/htdocs/provaVicky/provaVicky/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(638): Zend\ServiceManager\ServiceManager-> in /Applications/XAMPP/xamppfiles/htdocs/provaVicky/provaVicky/module/Film/Module.php on line 41

这里是文件"Module.php"

<?php 
namespace Film;

use Film\Model\Film;
use Film\Model\FilmTable;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;

 class Module implements AutoloaderProviderInterface, ConfigProviderInterface{

     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(
                 'Film\Model\FilmTable' =>  function($sm) {
                     $tableGateway = $sm->get('FilmTableGateway');
                     $table = new FilmTable($tableGateway);
                     return $table;
                 },
                 'FilmTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new Film());
                     return new TableGateway('film', $dbAdapter, null, $resultSetPrototype);
                 },
             ),
         );
     }
 }

他找不到的文件只是一个变量的实例,要检查它们是否为空。

我一直在关注这个Tutorial,但我不明白我做错了什么。

如果你们中有人能帮助我,我将非常高兴:D

谢谢你的建议, 罗伯托·兰扎

@ – Jannes Botis 这是目录结构。

- config
|--- module.config.php
- Model
|--- Film.php
|--- FilmTable.php
- src
|--- Film
|--- |--- Controller
|--- |--- |--- FilmController.php
- tests
|--- Film
|--- |--- Framework
|--- |--- |--- TestCase.php
|--- |--- SampleTest.php
|--- Bootsrap.php
|--- phpunit.xml
|--- TestConfiguration.php.dist
- view
|--- film
|--- |--- film
|--- |--- |--- foo.phtml
|--- |--- |--- index.phtml
- autoload_classmap.php
- autoload_function.php
- autoload_register.php
- license.txt
- Module.php
- README.md

据我所知,我的假设是您正在使用 PSR-4 规范来自动加载 类。 将目录 "Model" 移动到 "src/Film" 下。这样你就有 src/Film/Model".