How do you pass values between PHP pages for MVC?(你如何在 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 页面之间传递值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:你如何在 MVC 的 PHP 页面之间传递值?
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
