gpt4 book ai didi

php - Zend View Helper 中的数据库连接

转载 作者:可可西里 更新时间:2023-10-31 23:33:43 25 4
gpt4 key购买 nike

在 Zend View Helper 中使用数据库映射器是一种好习惯吗?因为在我的例子中,这个 helper 正在给我做一盒 <div>它会实时变化,并将显示在我的应用程序中的所有 View 中。我不可能让该对象从 Controller 中的数据库加载它并每次都将其分配给查看。

如果有人能告诉在使用 zend view helpers 时要遵循的良好编程实践,那将非常有帮助,例如:

  • 如果可以通过 $this->view->variable = ... ; 将某些内容分配给 View 助手中的 View
  • 如果可以在 View Helpers 中创建和使用模型。
  • 如果可以在 View Helper 中使用 Zend_View 可用的方法,比如 $this->view->baseUrl('...');

最佳答案

你的第二个和第三个要点对我来说似乎是正确的,只要你不从你的观点在你的模型中做任何逻辑的事情。模型和 View 之间的链接必须是只读的。

关于你的第一点,你不需要为 View 分配任何东西,你的 View 助手应该返回你的 HTML 输出直接到 View 。

关于您的第一个问题,您可以创建专用于此任务的 View 助手,因此您可以将其用作 View 助手和映射器之间的简单代理。一个 View 助手将允许您访问任何映射器,而其他 View 助手可以使用此 View 助手来获取映射器。

让我们看看 Trygve Reenskaug 对 MVC 的看法:

Models

Models represent knowledge. A model could be a single object (rather uninteresting), or it could be some structure of objects.

There should be a one-to-one correspondence between the model and its parts on the one hand, and the represented world as perceived by the owner of the model on the other hand.

Views

A view is a (visual) representation of its model. It would ordinarily highlight certain attributes of the model and suppress others. It is thus acting as a presentation filter.

A view is attached to its model (or model part) and gets the data necessary for the presentation from the model by asking questions. It may also update the model by sending appropriate messages. All these questions and messages have to be in the terminology of the model, the view will therefore have to know the semantics of the attributes of the model it represents.

Controllers

A controller is the link between a user and the system. It provides the user with input by arranging for relevant views to present themselves in appropriate places on the screen. It provides means for user output by presenting the user with menus or other means of giving commands and data. The controller receives such user output, translates it into the appropriate messages and pass these messages on to one or more of the views.

关于php - Zend View Helper 中的数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9481424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com