与php搭配使用MVC时的建议 [英] Advice when using MVC with php

查看:67
本文介绍了与php搭配使用MVC时的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用其中包含2个函数的一个视图文件是否正确?

Is it correct to use one view file with say 2 functions inside it.

例如,我的数据库中有项目表,并且在此特定的MySQL查询的视图文件中有2个函数.

For example I have project table in my database and I have 2 functions inside the view file for this specific MySQL query.

每个查询返回一个特定的视图,例如

Each query returns a specific view so say

函数1 = num_rows 功能2 =行内的数据

function 1 = num_rows function 2 = data inside the rows

这是正确的还是我应该做些不同的事情?

Would this be correct or should I do something different ?

推荐答案

您的视图文件中不应包含函数.

Your View Files should not have functions in them.

MVC的想法是分离模型,例如与表示层中的表示无关的所有内容(由V和C表示). M应该忽略V和C.

The idea of MVC is to separate the Model, e.g. everything not related to presentation from the presentation layer (represented by V and C). M should be oblivious to V and C.

控制器处理对表示层/用户界面的任何输入.它委派给模型,并设置模型返回给视图的所有内容.

The controller handles any input to the presentation layer / the User interface. It delegates to the Model and sets anything the Model returns to the View.

视图负责呈现模型数据和用户界面.如果需要在View中使用功能,最好将这些功能保存在View Helpers中.

The View is in charge of rendering your Model data and User Interface. If you need to have functions in the View, those are best kept in View Helpers.

请参见 PoEAA中的Web演示模式,以获取有关如何最好地呈现视图的一些想法. .

See the Web Presentation Patterns in PoEAA for some ideas about how to best render the View. Parts of the book are available on Google Books.

这篇关于与php搭配使用MVC时的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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