ZendFramework - 在模块化目录结构中的何处放置其他类? [英] ZendFramework - Where to place additional classes in modular directory structure?

查看:27
本文介绍了ZendFramework - 在模块化目录结构中的何处放置其他类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发某种基于 ZendFramework 的 Web 应用程序.在其中一个模块中,需要计算商品价格.购买时,通过提供一些促销代码,客户可以获得一个或多个折扣.

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).

计算价格的基类(方法getPrice")可以由多个装饰器类之一修改.它们中的每一个都可以减去一些值.因此,每个促销都有自己的类,实现了一些接口(例如使用方法getPrice")

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")

当然例子是简化的;)

我的问题是,将这些类(和接口)放在目录结构中的什么位置 *

My question is, where to place this bunch of classes (and interface) in directories structure *

*我使用默认的 ZF 模块化目录结构.

*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 :)

推荐答案

听起来你希望这些进入 application/modules/somemodule/models 所以像 Somemodule_Model_SomePromotion 这样的类> 将驻留在 application/modules/somemodule/models/SomePromotion.php 中.

Sounds like you want these to go into application/modules/somemodule/models so a class like Somemodule_Model_SomePromotion would reside in application/modules/somemodule/models/SomePromotion.php.

我相信模块化设置的默认资源自动加载器将被配置为从 models 文件夹中加载具有 hat 格式类名的模型.但如果没有,则将以下内容添加到模块(不是应用程序)Bootstrap 中:

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:

protected function _initResourceLoader()
{
    $resourceLoader = new Zend_Application_Module_Autoloader(array(
       'namespace' => 'Somemodule_',
       'basePath'  => dirname(__FILE__),
       'resourceTypes' => array(
            'models' => array(
                'namespace' => 'Model_',
                'path'      => 'models',
            ),
       ),
    ));
}

更新

@brady.vitrano 的每条评论:如果模块引导程序扩展了 Zend_Application_Module_Bootstrap,那么包含此映射的资源自动加载器将免费提供.无需手动包含,除非您希望添加其他资源类型.

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.

这篇关于ZendFramework - 在模块化目录结构中的何处放置其他类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆