问题描述
谁能提供一个非常简单的 MVC 方法中的 Hello World 示例?
Can anyone provide a very simple example of Hello World in MVC approach to PHP?
推荐答案
这里是一些Hello, World"MVC:
Here's some "Hello, World" MVC:
function get_users() { return array( 'Foo', 'Bar', 'Baz', ); }
查看
function users_template($users) { $html = '<ul>'; foreach ($users as $user) { $html .= "<li>$user</li>"; } $html .= '</ul>'; return $html; }
控制器
function list_users() { $users = get_users(); echo users_template($users); }
主要思想是将数据访问(模型)与数据表示(视图)分开.控制器应该做的只是将两者连接在一起.
The main idea is to keep separate the data access (model) from data presentation (view). The controller should be doing no more than wiring the two together.