本文介紹了PHP MVC 方法中的 Hello World 示例的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
誰(shuí)能提供一個(gè)非常簡(jiǎn)單的 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);
}
主要思想是將數(shù)據(jù)訪問(wèn)(模型)與數(shù)據(jù)表示(視圖)分開(kāi).控制器應(yīng)該做的只是將兩者連接在一起.
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.
這篇關(guān)于PHP MVC 方法中的 Hello World 示例的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!