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".

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度