Zend Framework 存储修改类的方式?
我有一个使用 Zend Framework 和 Zend_Translate 的项目。
我必须将标准 CSV 适配器稍微更改为 Zend_Translate。现在我面临的问题是把这个修改后的适配器放在哪里。
默认情况下,适配器存储在
/Library/Zend/Translate/Adapter/Adaptername.php
这也是我放置新适配器的位置。
但是,我不想用我的自定义扩展“污染”Zend 库:我希望能够更新 ZF,而不必担心丢失文件;我希望继续使用集中安装的 ZF 版本;自定义适配器确实是我正在开发的项目的一部分。
Zend Framework 是否有处理此问题的方法,或指定替代加载位置?
语言适配器是使用
$this->_adapter = new $adapter($data, $locale, $options);
(其中 $adapter
将是 Zend_Translate_Adapter_Adaptername
)
加载的,因此标准自动加载规则适用。有没有一种简单的方法可以告诉 Zend Autoloader 查看第二个位置?
I have a project that uses Zend Framework and Zend_Translate
.
I had to alter the standard CSV Adapter to Zend_Translate slightly. Now I'm confronted with the question where to put this altered adapter.
By default, adapters are stored in
/Library/Zend/Translate/Adapter/Adaptername.php
This is where I've put the new adapter as well.
However, I wouldn't like to "pollute" the Zend library with my custom extensions: I would like to stay able to update ZF without having to worry about losing files; I want to remain able to use a centrally installed version of ZF; and the custom adapter is part of the project I'm working on, really.
Is there a Zend Framework way of dealing with this, or specifying an alternative loading location?
Language adapters are loaded using
$this->_adapter = new $adapter($data, $locale, $options);
(Where $adapter
will be Zend_Translate_Adapter_Adaptername
)
so standard autoloading rules apply. Is there a simple way to tell the Zend Autoloader to look in a second location?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将其添加到 lib 文件夹中,
具体取决于自动加载器的设置方式, 你必须用它设置“命名空间”:
或者,如果你不喜欢这样,请将它放入你的模型文件夹中。基本上,你把它放在哪里并不重要,只要自动加载器可以以某种方式访问它即可。
Zend_Autoloader
可以注册任意自动加载器回调,所以这完全取决于你。You can add it to the lib folder
Depending on how your autoloader is setup, you have to setup the "namespace" with it:
Or, if you dont like this, put it into your models folder. Basically, it doesnt matter where you put it, as long as it is accessible somehow by the autoloader. The
Zend_Autoloader
can register arbitrary autoloader callbacks, so it's really up to you.由于该网站的规则,我无法对戈登的回答发表评论,但他是对的。要回答有关如何加载适配器的问题,您需要将完整的类名传递给翻译对象的构造函数:
组件首先检查 Zend 命名空间,以防您传递了短名称(例如“ gettext'),但随后将尝试直接将适配器名称作为类加载。
至少,在 1.10 中确实如此,而且我想这种情况已经有一段时间了。
I can't comment on Gordon's answer due to this site's rules, but he's got it right. To answer your question regarding how to load the adapter, you'll need to pass the full class name to the constructor of the translate object:
The component first checks in the Zend namespace in case you've passed in a short name (like 'gettext'), but will then attempt to load the adapter name as a class directly.
At least, this is true in 1.10, and I imagine has been for a while.