我对 PHP MVC 方法非常陌生,最近我遇到了从 View.php 显示表单的问题
代码在这里(Controller_Shipping.php)
<?php
include 'View_Shipping.php';
class Controller_Shipping{
public $view;
public function __construct(){
$this->view = new View_Shipping();
}
public function index(){
$this->view->showForm();
}
}
?>
视图文件如下所示(View_Shipping.php)
<?php
class View_Shipping{
public function showForm(){
?>
<form method="post">
<h3>Shipping Information</h3>
<p>
<label for="name"> Title Name </label>
<input type="text" id="name" name="Title" autofocus>
</p>
<p>
<button type = "submit"> Save </button>
</p>
</form>
<?php
} // end of showForm()
}
?>
当我通过“localhost/Controller_Shipping.php”加载它时,它什么也没有显示。但我创建了另一个非常非常简单的 php,比如“localhost/testing.php”,它只包含
<?php
include "Controller_Shipping.php";
$testing = new View_Shipping();
echo $testing->showForm();
?>
有用。来到控制器它失败了..它是否与为控制器类分配一个新对象有关?