如何在MVC的PHP页面之间传递值? [英] How do you pass values between PHP pages for MVC?

查看:128
本文介绍了如何在MVC的PHP页面之间传递值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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页面之间传递值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆