ZendFramework - 在模块化目录结构中的何处放置附加类?
我目前正在开发某种基于 ZendFramework 的 Web 应用程序。 在其中一个模块中需要计算商品价格。 购买时,通过提供一些促销代码,客户可以获得一项或多项折扣。
我想把它作为装饰器(模式)。
计算价格的基类(方法“getPrice”)可以通过多个装饰器类之一进行修改。它们每个都可以减去一些值。 因此,每个促销都有自己的类实现一些接口(例如使用方法“getPrice”)
当然示例被简化了;)
我的问题是,在目录结构中将这堆类(和接口)放在哪里*
*我正在使用默认 ZF 的模块化目录结构。
他们与模特有一些共同点,也许是助手?但绝对与视图没有任何共同点...
另一件事是,它们应该与模块绑定,所以它们应该放置在该模块文件夹中。
任何帮助,任何想法将不胜感激:)
I'm currently working on some kind of web application based on ZendFramework.
In one of the modules there's a need of calculating item price.
When buying, by providing some promotional code client can get access to one or more discounts.
I thought of making it as decorators (pattern).
Base class calculating price (method "getPrice") can be modified by one of more decorator classes. Each of them can substract some value.
So, each promotion has its own class implementing some interface (e.g. with method "getPrice")
Of course example is simplified ;)
My question is, where to place this bunch of classes (and interface) in directories structure *
*I'm using default ZF's modular directory structure.
They have something in common with models, maybe helpers? But definitely nothing in common with views...
Another thing is, that they should be bound with module, so they should be placed in that module folder.
Any help, any ideas will be appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您希望这些进入
application/modules/somemodule/models
,因此像Somemodule_Model_SomePromotion
这样的类将驻留在application/modules/somemodule/models/SomePromotion 中。 php
.我相信模块化设置的默认资源自动加载器将配置为从
models
文件夹加载具有 hat 格式的类名的模型。但如果没有,则将以下内容添加到模块(而不是应用程序)引导程序中:更新
@brady.vitrano 的每条评论:如果模块引导程序扩展
Zend_Application_Module_Bootstrap
,则包含此映射的资源自动加载器是免费的。无需手动包含它,除非您希望添加其他资源类型。Sounds like you want these to go into
application/modules/somemodule/models
so a class likeSomemodule_Model_SomePromotion
would reside inapplication/modules/somemodule/models/SomePromotion.php
.I believe that the default resource autoloader for a modular setup will be configured to load models with classnames of hat format from that
models
folder. But if not, then add the following into the module (not the app) Bootstrap:Update
Per Comment by @brady.vitrano: If the module bootstrap extends
Zend_Application_Module_Bootstrap
, then a resource autoloader containing this mapping comes for free. No need to include it manually, unless you wish to add other resource types.您应该像这样构建自己的库:
您的类名称是
Package_Subpackage_ClassName
。您还应该将Package_
前缀添加到自动加载器。You should structure your own library like this:
Where your class name is
Package_Subpackage_ClassName
. You should also add yourPackage_
prefix to the autoloader.