php – MVC Zend Framework中的类自动加载不起作用

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – MVC Zend Framework中的类自动加载不起作用脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我在MVC zend框架中完成了我的第一个Web应用程序,一切都在我的localhost上运行良好.

所以我把它上传服务器上,自动加载我的课有问题.
当我想在indexcontroller中从我的类创建对象时,我收到错误消息:

$this->view->bottomCache = new Application_Model_Cache($this->cacheTime,'bottomCache');

我得到这个错误的消息:

Fatal error: Class 'Application_Model_Cache' not found in ........./IndexController.PHP on line 19

在我的本地主机上,我使用的是Zend Server CE,它可以运行.

拜托,你能给我一些建议,我会检查一下,知道它为什么不起作用?

解决了:
类的名字的第一个字母必须是大写的,Cache.PHP

EDIT2:
文件夹模型与模型
正如你在这example中看到的那样

// application/models/GuestBook.PHP

class Application_Model_Guestbook
{

EDIT1:
我在http://framework.zend.com/manual/en/learning.quickstart.create-project.html使用了教程,所以我使用了文件结构.

quickstart
|-- application
|   |-- Bootstrap.PHP
|   |-- configs
|   |   `-- application.ini
|   |-- controllers
|   |   |-- ErrorController.PHP
|   |   `-- IndexController.PHP
|   |-- models
|   |   |-- cache.PHP
|   |   `-- DBTable
|   |       `-- Downloaded.PHP
|   `-- views
|       |-- helPErs
|       `-- scripts
|           |-- error
|           |   `-- error.phtML
|           `-- index
|               `-- index.phtml
|-- library
|-- public
|   |-- .htaccess
|   `-- index.PHP

bootstrap.PHP
在我的靴带我有

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
  PRotected function _initAutoload() {

        $autoloader = new Zend_Application_Module_Autoloader(array(
                    'namespace' => 'Application_','basePath' => dirname(__FILE__),));;
        $autoloader->addResourceType('model','model/','Model');
        return $autoloader;
  }

  protected function _initDoctype()
  {
    $this->bootstrap('view');
    $view = $this->getResource('view');
    $view->doctype('XHTML1_TRANSITIONAL');
  }
}

的application.ini

[production]
PHPSettings.display_startup_errors = 0
PHPSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.PHP"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
PHPSettings.date.timezone = "Europe/London"
resources.db.adapter = PDO_MysqL
resources.db.params.host = localhost
resources.db.params.username = *****
resources.db.params.password = ****
resources.db.params.dbname = *****
resources.db.params.charset = "utf8" 
resources.db.params.names = "utf8" 
resources.view.doctype = "XHTML1_TRANSITIONAL"

[staging : production]

[testing : production]
PHPSettings.display_startup_errors = 1
PHPSettings.display_errors = 1

[development : production]
PHPSettings.display_startup_errors = 1
PHPSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

解决方法

EDIT2:
你必须调用你的cache.PHP文件Cache.PHP.它的情况是敏感的.试试吧.

编辑:在你的结构中它是一个模型(见s)文件夹.你用这个调用

Application_Model_Cache

所以ZF正在application / model /中寻找它.

所以把你的班级改为

Application_Models_Cache

不要忘记在类代码中执行此操作.或者文件名称更改为模型(似乎所有代码引用模型,因此更改文件夹似乎是最快的方式.

@H_126_70@

脚本宝典总结

以上是脚本宝典为你收集整理的php – MVC Zend Framework中的类自动加载不起作用全部内容,希望文章能够帮你解决php – MVC Zend Framework中的类自动加载不起作用所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。