Warning: include_once(Application/Model/Hiring.php): failed to open stream:
No such file or directory in /var/www/hiring/library/Zend/Loader.php on line 146在包含路径中
Warning: include_once(): Failed opening 'Application/Model/Hiring.php' for inclusion
(include_path='/var/www/hiring/application/../library:/var/www/hiring/library:./application
/models/:./application/controllers/:./application/views/scripts/:.:/usr/share/php:/usr/local
/ZendFramework/library') in /var/www/hiring/library/Zend/Loader.php on line 146我的索引文件是
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
// define root path
defined('ROOT_PATH') || define('ROOT_PATH', realpath(dirname(__FILE__) . '/'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(realpath(dirname(__FILE__) . '/library')
. PATH_SEPARATOR . './application/models/'
. PATH_SEPARATOR . './application/controllers/'
. PATH_SEPARATOR . './application/views/scripts/'
. PATH_SEPARATOR . get_include_path());
require_once 'Zend/Application.php';
require_once 'Zend/Loader/Autoloader.php';
/** Zend_Application */
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('hiring');
$loader->setFallbackAutoloader(true);
Zend_Loader::loadClass('Zend_Controller_Front');
Zend_Loader::loadClass('Zend_Config_Ini');
Zend_Loader::loadClass('Zend_Registry');
Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Db_Table');
Zend_Loader::loadClass('Zend_Db_Statement');
//Zend_Loader::loadClass('Zend_Mail_Transport_Smtp');
//Zend_Loader::loadClass('Zend_Mail_Transport_Sendmail');
//Zend_Loader::loadClass('Zend_Mail');
Zend_Loader::loadClass('Zend_Session_Namespace');
Zend_Loader::loadClass('Zend_Db_Adapter_Pdo_Pgsql');
//Zend_Loader::loadClass('Zend_Date');
Zend_Loader::loadClass('Zend_Log');
// setup controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(false);
$frontController->setBaseUrl('http://hiring.local');
$frontController->setControllerDirectory('/application/controllers');
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()->run();为什么我会得到这个错误我查看了loader.php在146行的那一行
include_once($filename),所以错误是从那里产生的
发布于 2013-01-15 17:56:09
这里有很多问题:
application/models,application/controllers和application/views/scripts不应在包含路径上。$loader->registerNamespace('hiring');可能应该是$loader->registerNamespace('Hiring_'); (尽管在您所包含的代码示例中没有迹象表明您正在使用这个名称空间)。$loader->setFallbackAutoloader(true);可能不是必需的(在您包含的代码示例中没有迹象表明您需要这样做)。Zend_Loader::loadClass行都应该删除。自动加载器的全部意义在于,您不需要自己在中。
但这些都不会影响您报告的问题。标准的自动加载器设置将只加载其名称可以直接映射到文件系统的类(通过将下划线转换为路径中的斜杠,例如,类Zend_Db_Table将位于library/Zend/Db/Table.php)。类Application_Model_Hiring不适合此模型,如果您还想使用此命名方案,则还需要设置一个资源自动加载器,它仅将类名的最后一部分映射到application/中的一些预定义的子文件夹。
将以下方法添加到bootstrap类中:
protected function _initAutoloader()
{
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Hiring_');
$applicationResourceAutoloader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => APPLICATION_PATH,
'namespace' => 'Application'
));
$autoloader->pushAutoloader($applicationResourceAutoloader);
return $autoloader;
}这将设置标准的自动加载器($autoloader = Zend_Loader_Autoloader::getInstance();),它将自动加载Zend Framework类。然后,它会注册一个名称空间'Hiring',只有在库文件夹中包含以该名称开头的类时才需要该名称空间。
然后,它使用命名空间' application‘创建一个单独的资源自动加载器,它将从应用程序文件夹中加载类,包括模型。假设类Application_Model_Hiring是在application/models/Hiring.php中定义的,那么它应该可以工作。
欲了解更多信息,请访问http://framework.zend.com/manual/1.12/en/zend.loader.autoloader-resource.html
https://stackoverflow.com/questions/14331887
复制相似问题