Zend 框架中类似 Magento 的代码池
我真的很喜欢 Magento 使用代码池的方式,这样就可以在不实际更改代码核心功能的情况下扩展类和功能。
(对于那些不熟悉 Magento 的人,您可以在“核心”代码池和“本地”代码池中拥有相同的类,当您创建一个类时,它首先在“本地”代码池中查找,如果不存在,则查看“核心”代码池)
我知道 Magneto 使用 Zend Framework,所以我想知道 Varien 是否使用了 Zend Framework 中已有的内容,或者他们自己这样做了?或者如果有人知道在 Zend Framework 中是否有有效地做到这一点的好方法?
I really like the way that Magento uses code pools so that classes and functionality can be extended without actually changing the core functionality of the code.
(for those not familiar with Magento you can have the same class in the "core" code pool and the "local" code pool and when you create a class it first looks in the "local" code pool and if it does not exist it looks in the "core" code pool)
I know that Magneto uses the Zend Framework so I was wondering if Varien used something already inside of the Zend Framework of if they did this themselves? Or if someone knows if there is a good way to effectively do this in Zend Framework?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道 Magento 如何做到这一点(提示:查看他们的源代码),但您可能可以使用
Zend_Autoloader
,例如,当尝试加载类Foo_Bar_Baz
时,自动加载器将首先查找Local/Foo/Bar/Baz
,如果该文件不存在,它将尝试从Core/Foo/Bar/Baz
加载。I dont know how Magento does that (tipp: look at their sourcecode), but you could probably achieve the same with
Zend_Autoloader
, e.g. when trying to load classFoo_Bar_Baz
the autoloader will first look inLocal/Foo/Bar/Baz
and if the file isn't there it will try to load fromCore/Foo/Bar/Baz
.