phpzend-frameworkzend-studiozend-server

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


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

Solution

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