drh96824 2017-02-19 16:54
浏览 79
已采纳

[PHP] [Zend]致命错误:未捕获错误:类'电影\模型\电影'

I'm going to learn Zend Framework, and when I was trying to create a new module that has to read some info from the DB, I got stuck with this error:

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

Here the file "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);
                 },
             ),
         );
     }
 }

The file that he can't found is just an instance of the variables to check if they're empty or not.

I was following this Tutorial, but I can't understand what I have done wrong.

If someone of you could help me I'll be very glad :D

thank you in advice, Roberto Lanza

@ – Jannes Botis Here is the directory structure.

- 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
  • 写回答

1条回答 默认 最新

  • duanjiuhong5843 2017-02-20 18:45
    关注

    From what I see, my assumption is that you are using PSR-4 specification for autoloading your classes. Move directory "Model" under "src/Film". So that you have src/Film/Model".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页