如何指示我的自定义类所在的 zend 框架 [英] How to indicate zend framework where my custom classes are
本文介绍了如何指示我的自定义类所在的 zend 框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 ZF 1.10 应用程序中有一个包含自定义类的文件夹.该文件夹位于/library 中.我怎么能告诉采埃孚他们在哪里?application.ini 和 index.php 都设置了库的路径,但 ZF 找不到文件.
I have a folder with custom classes in a ZF 1.10 application. The folder is located in /library. How can I tell ZF where they are? Both application.ini and index.php set the path to the library but then ZF can't find the files.
谢谢
推荐答案
有很多可能的解决方案.最常见的,当使用 Zend Application 时,是在 application.ini
中通过添加:
There are many possible solutions. The most common, when using Zend Application, is to register the namespace in application.ini
by adding:
autoloaderNamespaces[] = "Example_"
其他解决方案:
- 使用
set_include_path()
(临时解决方案)将您的目录添加到include_path
- 遵循 PEAR 命名约定(因此可以进行路径解析)
- Add your dir to
include_path
usingset_include_path()
(ad hoc solution) - Follow PEAR naming conventions (so the path resolving was possible)
在Bootstrap.php
中设置自动加载器:
protected function _initAutoloader()
{
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace("Example"); // or Example_
}
最终,设置模块或资源自动加载器,例如.
Eventually, set up module or resource autoloader, eg.
$resourceLoader->addResourceTypes(array(
'acl' => array(
'path' => 'acls/',
'namespace' => 'Acl',
),
'example' => array(
'path' => 'examples/',
'namespace' => 'Example',
),
));
这篇关于如何指示我的自定义类所在的 zend 框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文