简单的模型 - 视图 - 分离 [英] Simple model-view -separation

查看:49
本文介绍了简单的模型 - 视图 - 分离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用php构建一个相当小的(最多10个不同页面)网站

,而且我很明显我需要某种模型

查看分离。


完成了一些搜索,我发现了''模板

引擎'的概念,但是这对我的需求来说似乎有些过分。我在想,我会坚持使用php作为我的模板语言。一个小的嵌入式代码在

视图页面,for循环或其他什么,应该没问题。


我想出了以下''架构'',但在我开始工作之前想要一些

反馈。

我网站的核心是''index.php''。每个请求都会转到

页面,其中包含用于选择目标页面的参数。

" index.php?a = home"," index .php?a = news"等等。


基于该参数,控制器创建一个类

的实例来处理该类型的请求。


一个'if-else / switch''块包含包含逻辑

(模型)文件的文件,创建一个类的实例在里面?

或者我应该创建名为model / home.php,model / news.php的文件。并且

动态地包含这些?


如何命名类或内部的任何内容?相同的名称,但

包含的不同文件可能有效,但听起来像是poooor设计。

创建类$ somestring可行的实例?

一次逻辑加载后,我打算调用

$ requestHandler-> service(),这将以某种方式准备我们计划显示的数据。设置一个全局变量是否可以完成这项工作?


$ requestHandler-> service() - 或者我应该只使用全局函数,

只会是一个包括在内,但我最好把它放在一个

类,对吗? - 还返回一个字符串,这是正确的

''视图'的网址。


此页面包含(?)d,和,使用全局声明的

$ myTableData,它为

用户的浏览器提供了一个包含数据表的好页面。?

解决方案

somestring doable?

加载逻辑后,我打算调用


< blockquote> requestHandler-> service(),它将以某种方式准备我们计划显示的数据。设置一个全局变量是否可以完成这项工作?


requestHandler-> service() - 或者我应该只使用全局函数,

只会包含一个,但我最好将它放在

类中,对吗? - 还返回一个字符串,这是正确的

''视图'的网址。


此页面包含(?)d,和,使用全球声明的


I''m trying to build a fairly small (max. 10 different pages) site
using php, and it''s becoming obvious that I need some kind of model
view separation.

Having done a few searches, I''ve come across the concept of ''template
engines'', but that seems like overkill for my needs. I''m thinking I''ll
just stick with php as my template language; a little embedded code in
the view pages, for loops or whatever, should be ok..

I''ve come up with the following ''architecture'', but would like some
feedback before i start working on it.
The heart of my site will be ''index.php''. Every request goes to that
page, with a parameter for picking the target ''page''.
"index.php?a=home", "index.php?a=news", and so on.

Based on that parameter, the controller creates an instance of a class
for handling that type of request.

An ''if-else/switch'' block including the file containing the logic
(model) file, creating an instance of the class inside?
Or should I create files named "model/home.php", "model/news.php" and
include these dynamically?

How do I name the classes or whatever''s inside? Same name, but
different file included might work, but sounds like poooor design.
Creating an instance of class $somestring doable?
Once the logic is loaded, I plan on calling
$requestHandler->service(), which will somehow prepare the data we
plan on displaying. Will setting a global variable do the job?

$requestHandler->service() - or should i just use a global function,
there will only be one included, but I am better off placing it in a
class, right? - also returns a string, which is the url to the correct
''view''.

This page is then include(?)d, and, using the globally declared
$myTableData, it puts up a nice page with a table of data for the
user''s browser..?

解决方案

somestring doable?
Once the logic is loaded, I plan on calling


requestHandler->service(), which will somehow prepare the data we
plan on displaying. Will setting a global variable do the job?


requestHandler->service() - or should i just use a global function,
there will only be one included, but I am better off placing it in a
class, right? - also returns a string, which is the url to the correct
''view''.

This page is then include(?)d, and, using the globally declared


这篇关于简单的模型 - 视图 - 分离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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