問題描述
PHP 程序如何在模型、視圖和控制器頁面之間傳遞值?例如,如果控制器有一個(gè)數(shù)組,它如何將它傳遞給視圖?
How do PHP programs pass values between model, view, and controller pages? For example, if a controller had an array, how does it pass that to the view?
感謝您的回答.我看到其中一些聲明組件在同一頁面中,但是當(dāng)我查看類似 CodeIgniter 的內(nèi)容時(shí),我看到三個(gè)單獨(dú)的 PHP 頁面分別用于模型、視圖和控制器.
Thank your answers. I see a couple of them stating the components are in the same page, but when I look at something like CodeIgniter, I see three separate PHP pages for model, view, and controller.
推薦答案
通常你的控制器會創(chuàng)建一個(gè)視圖對象,當(dāng)它創(chuàng)建那個(gè)視圖對象時(shí),它會傳遞信息.
Usually your controller will create a view object and when it creates that view object it passes the information.
<?php
class Controller {
public function __construct() {
$arr = array("a","b","c");
$myView = new View($arr);
}
}
class View {
private $content;
public function __construct($content) {
$this->content = $content;
include_once('myPage.inc.html');
}
}
?>
這篇關(guān)于你如何在 MVC 的 PHP 頁面之間傳遞值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!