php - 您如何在 MVC 的 PHP 页面之间传递值?

标签 php model-view-controller

PHP 程序如何在模型、 View 和 Controller 页面之间传递值?例如,如果 Controller 有一个数组,它如何将其传递给 View ?

编辑:

感谢您的回答。我看到他们中有几个说组件在同一个页面中,但是当我查看类似 CodeIgniter 的东西时,我看到了模型、 View 和 Controller 的三个单独的 PHP 页面。

最佳答案

通常您的 Controller 会创建一个 View 对象,当它创建该 View 对象时,它会传递信息。

<?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');
    }
}


?>

关于php - 您如何在 MVC 的 PHP 页面之间传递值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3833324/

相关文章:

php - 如何使用PHP正确连接到MariaDB数据库

c# - Serenity-将表单中的值添加到 2 个表中

iOS MVC 架构 - 除了 View Controller 的 View 之外的独立 View

javascript - Sailsjs websockets 文档去哪儿了?

php - Codeigniter 2.2.2/如何打印从 Controller 传入的 "View"中的数组数据?

php - 如何在PHP中检查它是普通字符串还是二进制字符串?

php - 使用来自 ajax 请求的原始数据作为背景图像

grails - 在 View 定义中生成的实例

asp.net-mvc - 我如何在 mvc actionlink 语法中添加 Bootstrap 图像?

javascript - 如何高亮显示当前页面的菜单链接?