gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 00:17:29 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com