尝试学习 PHP MVC。到目前为止一切都很好,直到这一刻。我的 ./controllers/index.php 中有这样的功能
<?php
class Index extends Controller {
function __construct() {
parent::__construct();
}
function showFeeds() {
return 'done';
}
}
?>
我知道如何调用模型类并在模型类上运行 showFeed() 。我的问题是如何在我的 ./views/index.php 上打印“完成”。有什么选择。
我已经尝试过下面列出的其中一些。但运气不佳。
- 父级::showFeeds()
- $this->controller->showFeeds();
最佳答案
终于解决了我的问题
页面:/controllers/index.php
<?php
class Index extends Controller {
function __construct () {
parent::__construct ();
}
function showFeeds () {
return 'done';
}
}
?>
页面:./views/index/index.php
<?php
$_index = new Index ();
$params = $_index -> showFeeds ();
?>
关于PHP MVC 从 View 调用 Controller 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17425765/