1

我是zend框架的新手,

一个简单的问题:

在我的 IndexController 文件中,我想实例化新类。

我把类声明文件放在/library下

当然它在包含路径中(index.php)

set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path()
)));

我收到一个错误:

Fatal error: Class 'Profile' not found in ....

自动加载此类的方法是什么?

谢谢!

4

2 回答 2

6

或者,您可以将命名空间添加到自动加载器。

因此,如果您的类被命名并My_Profile存储在文件library/My/Profile.php中,您可以将以下内容添加到您的application/config/application.ini

autoloadernamespaces[] = "My_"

或在您Bootstrap班级的_initAutoload()方法中:

Zend_Loader_Autoloader::getInstance()->registerNamespace('My_');

请参阅Zend 框架:自动加载类库

于 2010-07-15T17:53:09.800 回答
2

你必须把这个类放在模型中......而不是放在库中并使用

set_include_path('./application/models'); in index.php
于 2010-07-15T11:08:38.850 回答