谁能提供一个非常简单的 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.
这篇关于PHP MVC 方法中的 Hello World 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Zend 中的动作视图助手 - 解决方法?Action View Helper in Zend - Work around?(Zend 中的动作视图助手 - 解决方法?)
这是将 URI 与 PHP 中用于 MVC 的类/方法匹配的好方Is this a good way to match URI to class/method in PHP for MVC(这是将 URI 与 PHP 中用于 MVC 的类/方法匹配的好方法吗)
我在哪里保存 Zend Framework 中的部分(视图),以便Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(视图),以
有一个网站的单一入口点.坏的?好的?没问题?Having a single entry point to a website. Bad? Good? Non-issue?(有一个网站的单一入口点.坏的?好的?没问题?)
MVC + 服务层在 Zend 或 PHP 中常见吗?Is MVC + Service Layer common in zend or PHP?(MVC + 服务层在 Zend 或 PHP 中常见吗?)
关注点分离;MVC;为什么?Separation of concerns; MVC; why?(关注点分离;MVC;为什么?)