我正在努力将 clientId 从表单获取到模型。我正在使用 netbeans 11.1 和 php 7.4。我正在关注某个教程,这是我尝试过的,首先是我的模型,它扩展了定义数据库连接的基本模型:
<?php
class Clients_Model extends Model {
function __construct() {
parent::__construct();
$clientId = filter_input(INPUT_POST, $clientId);
}
public function run($clientId = null){
$statement = $this->db->prepare("SELECT * FROM client WHERE clientId
= :clientId");
$statement->execute(array(':clientId' => $clientId));
$data = $statement->fetchAll();
print_r($data);
}
}
?>
接下来是控制器:
<?php
class Clients extends Controller {
function __construct() {
parent::__construct();
}
function index(){
$this->view->render('clients/index');
}
function run(){
$this->model->run();
}
}
?>
和观点:
<div id="content">
<h3>Client Booking</h3>
<form action="clients/run" method="post">
<label for="clientId">Client Id:</label><br>
<input type="text" name="clientId" id="clientId"><br>
<input type="submit" name="submit"><br>
</form>
</div>
视图在 render 函数中呈现如下:
<?php
class View {
function __construct() {
}
public function render($name, $same = false){
if ($same == true){
require 'views/' .$name. '.php';
}else{
require 'views/header.php';
require 'views/' .$name. '.php';
require 'views/footer.php';
}
}
}
?>
错误是get如下:
> Notice: Undefined variable: clientId in C:\xampp\htdocs\healthMentor\models\clients_model.php on line 8
Array ( )