我将学习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
答案 0 :(得分:0)
从我看到的情况来看,我的假设是您正在使用PSR-4规范来自动加载您的类。 在“src / Film”下移动目录“Model”。所以你有src / Film / Model“。