PHP 程序如何在模型、视图和控制器页面之间传递值?例如,如果控制器有一个数组,它如何将它传递给视图?
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?
感谢您的回答.我看到其中一些声明组件在同一页面中,但是当我查看类似 CodeIgniter 的内容时,我看到三个单独的 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.
通常你的控制器会创建一个视图对象,当它创建那个视图对象时,它会传递信息.
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');
}
}
?>
这篇关于你如何在 MVC 的 PHP 页面之间传递值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!