Zend Framework 1.10 重写类调用?

发布于 2024-11-03 23:45:16 字数 286 浏览 0 评论 0原文

我想我试图变得过于聪明。如果有效的话,耶。如果没有,不用担心。

我希望我的应用程序尽可能模块化。目前我只有一个产品模块,但根据经验,我知道我可能还需要一个类别模块,其中产品将是其子模块。虽然类别模块不存在,但我希望调用 Products_Forms_NewProduct 等来加载表单。当类别模块放入应用程序时,我希望它能够被自动检测并转发任何调用,例如,将 Products_Forms_NewProduct 转发到 Categories_Forms_NewProduct。

我该怎么办?

I think I am trying to be overly clever. If it works, yay. If not, no worries.

I want my application to be as modular as possible. At the moment I have just a products module but from experience I know I might want a categories module as well, in which products will be children of. Whilst the categories module does not exist I want calls to, for example, Products_Forms_NewProduct to load that form. When the categories module is dropped into the application I want it to be automatically detected and forward any calls for, for example, Products_Forms_NewProduct to Categories_Forms_NewProduct.

How do I go about this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木落 2024-11-10 23:45:16

在我看来,您正在寻找依赖注入。但我建议开设一个可以适当修改表格的课程。就像一个表单插件。这不是扩展,而是组合。我会遵循这些原则:

// say in Form_NewProduct's init()
$this->addPlugin(new Form_Plugin_Category());
$this->addSubform(new Form_NewProduct_ProductSubform());

//in plugin or in form directly
if (class_exists('Form_NewProduct_CategorySubform')) {
    $this->_form->addSubform(new Form_NewProduct_CategorySubform());
}

You're looking for dependency injection IMO. But I'd suggest having a class that would modify the form appropriately. Like a form-plugin. This is no case of extension, but rather composition. I'd go with something alon those lines:

// say in Form_NewProduct's init()
$this->addPlugin(new Form_Plugin_Category());
$this->addSubform(new Form_NewProduct_ProductSubform());

//in plugin or in form directly
if (class_exists('Form_NewProduct_CategorySubform')) {
    $this->_form->addSubform(new Form_NewProduct_CategorySubform());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文