Zend Framework :: 一般应用程序设计问题
我刚刚开始学习 Zend(以及 OO PHP),我花了过去 4-5 周的时间学习、教程、书籍等。我对此感觉很好,但会陷入模型的泥沼(没关系,我学习)。我现在开始我的第一个应用程序(甚至用于工作);它至少有 5 个主要部分(包括登录 + 需要 ACL),有几个部分最多有 10-12 个子部分,例如管理:创建用户、编辑用户等。
我创建了一个布局,并制作了大部分带有工作链接的页面视图,并且已经完成了一些表格。
我现在主要关心的是我是否应该在失控之前重构并制作主要部分的模块,或者我什么都不担心。我认为我做错的一件事是,我有一个“AdminController”,它除了引入管理“视图”之外什么也不做,它只不过是指向“UserController”中每个“用户”操作的链接。我想也许我应该将用户操作放在 AdminController 中。我也在想,我应该制作一个“管理”模块、“报告”模块、“身份验证”模块等。或者最终拥有 8 个控制器并不断增长是否正常?我已经倾向于为了我自己的理智而制作和维护开发人员的站点地图,更不用说我想尽最大可能:)
I just started learning Zend (& OO PHP for that matter), I have spent the last 4-5 weeks learning, tutorials, books etc. I feel good about it but will bog down in the models (thats ok, I'm learning). I am now beginning my first app (for work even); It has at least 5 major sections (including the login + will need ACL), and a couple will have up to 10-12 sub sections like admin: create user, edit user, etc.
I created a single layout, and have made most of the page views with working links, and have a few of the forms complete already.
My major concern now is should I refactor and make modules of the major sections before it gets out of hand, or am I worried about nothing. One thing I think I did wrong is that I have a 'AdminController' that does nothing but bring in the admin 'view' that is nothing more than links to each 'user' action in the 'UserController'. I'm thinking maybe I should have put the user actions in the AdminController. I'm thinking too, that I should make a 'admin' module, 'reports' module, 'auth' module, etc. Or is it normal to end up with 8 controllers and growing? I already have the inclination to make and maintain a developer's sitemap just for my own sanity, not to mention that I want to do the best job possible :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原则上,我喜欢为每组功能(新闻、用户、画廊等)提供可插件模块的想法。“插入”该模块将为后端管理和前端显示提供功能。它是一个独立的地方,可以放置所有功能 - 模型、操作助手、视图助手、视图脚本。等等 - 您需要该内容区域。每个模块可能有两个控制器 - News_BackendController 和 News_FrontendController - 专用于其特定区域。
但在实践中,我发现采埃孚模块让这变得困难。我知道比我更聪明的人——当然,门槛很低——可以让这一切成功,但我从来没有运气。
所以我通常会得到两个模块——前端和后端。例如,对于新闻功能,我会在后端模块中有一个新闻控制器来管理内容;前端模块中的另一个新闻控制器用于显示它。
对我来说,此设置的难点在于将前端和管理通用的模型功能放在哪里。一种想法是将其放在一个单独的库中,然后创建特定于模块的模型,以扩展这些模型以实现任何特定于模块的功能。类似于:
MyLibary_Model_News
用于常见新闻内容。Frontend_Model_News 扩展了 MyLibrary_Model_News
以实现任何仅限前端的新闻功能(如果有)。Admin_Model_News 扩展了 MyLibrary_Model_News
以实现任何仅限后端的新闻功能(如果有)。只是一些想法。一如既往,YMMV。
In principle, I like the idea of a plugin-able module for each set of functionality - News, Users, Galleries, etc. "Plugging in" that module would provide functionality for the back-end admin and the front-end display. It is a self-contained place to put all the functionality - models, action helpers, view helpers, view scripts. etc - that you need for that content area. There might be two controllers per module - News_BackendController and News_FrontendController - dedicated to their specific areas.
But in practice, I find that ZF modules make that hard. I know that smarter guys than me - a low bar, to be sure - can make it all work, but I've never had luck with it.
So I usually end up with two modules - frontend and backend. For news functionality, for example, I'd have a news controller in the backend module for managing the content; another news controller in the frontend module for displaying it.
The sticky point for me in this setup is where to put model functionality that is common to both frontend and admin. One idea is to put it out a separate library and then create module-specific models that extend these for any module-specific functionality. Something like:
MyLibary_Model_News
for the common news stuff.Frontend_Model_News extends MyLibrary_Model_News
for any frontend-only news functionality, if any.Admin_Model_News extends MyLibrary_Model_News
for any backend-only news fnctionality, if any.Just some ideas. As always, YMMV.