view中使用了逻辑,如何取出来
对于一个项目,我在我看来使用了一些逻辑,这不是正确的方法,所以我想把它拿出来。
问题是它无法从我的模型的类方法中完成,因为 Zend 将从 10000 个实例到数据库进行 10000 次查询,并且它变得非常慢。
因此,我必须一次性加载所有数据,然后对其进行处理并将数据返回到视图。在我看来,它的工作方式与我的方式相同,唯一的问题是它位于视图文件中。
该怎么走呢?只需在模型中创建一个类来输入值并返回所需的数据?
谢谢
For a project I used some logic in my view, this is not the way to go so I want to get it out.
The problem is that it can't be done from a class method of my model because Zend will make 10000 of queries from 10000 of instances to the database and it becomes very slow.
So I have to do it on a way that it loads all data at once, then processes it and returns the data back to the view. In my view it works the way I do it, the only problem is that it is IN the viewfiles.
What is the way to go? Just make a class in the model that inputs the values and returns required data?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我从 MVC 角度显示数据的方式
Controller
你必须在模型中进行逻辑处理(在上面的示例中,它通过 process 方法在静态类 DataProcessor 中完成(不是必然是要走的路,但这可能是一个好的开始)
查看
或
最后,您应该尝试使模型尽可能灵活,使其可重用,这就是oop 开发的关键。
Here is the way i would go to display data from a MVC perspective
Controller
You have to do your logic processing in a model (in the example above its done in the static class DataProcessor throught the process method (Not neccessarly the way to go, but it could be a good start)
View
or
Finally, you should try to make your models as flexible as possible to make them reusable which is the key in oop development.