我对 PHP 完全是个菜鸟,但对 OO 有很好的工作知识。我正在开发一个显示个人资料的项目。我有一个profile.php,它获取患者的身份证号并创建一个人员对象,然后在下面呈现一个 html 模板。html 模板应该显示患者的生命体征和其他信息。我有三个插件,其中两个工作。
我遇到的问题是,profile.php
我创建了一个$person
对象,并且我通过输出 $person 的全名和 ID 验证了它的工作原理。但是,当呈现 html 模板时profile.html
.... $person 似乎在那里不可见,特别是/inserts/_patient_form.php
它似乎无法访问我的$person
对象。有什么我做错了吗?仍在尝试了解 php 的各种怪癖......我应该声明一些全球性的东西吗?
配置文件.php
<?php
include_once('../mysql_connect.php');
include_once('includes/classes/person.php');
include_once('includes/classes/stats.php');
include_once('includes/classes/note.php');
include_once('includes/classes/prescription.php');
include_once('includes/functions.php');
//Define the query
if (isset($_GET['patient']) && is_numeric($_GET['patient']) && ($_GET['patient'] > 0)){
$person = Person::find_by_id($_GET['patient']);
$name = $person->getFullName();
$id = $person->getId();
define('TITLE', $name . '\'s Profile');
include('templates/header.html');
include('templates/profile.html');
include('templates/footer.html');
} else { // Couldn't get the information
define('TITLE', 'Invalid Profile');
include('templates/header.html');
print '<p class="error">This is an invalid page, or this patient doesn\'t exist..</p>';
include('templates/footer.html');
}
mysql_close($dbc);// Close the connection
?>
profile.html
<h2 style="margin-bottom:10px;"><?php print $name ?></h2>
<p id="message"></p>
<ul class="nav nav-tabs" id="patient-tabs">
<li class="active"><a href="#statistics" data-toggle="tab">Statistics</a></li>
<li><a href="#notes-prescriptions" data-toggle="tab">Notes and Prescriptions</a></li>
<li><a href="#profile" data-toggle="tab">Profile</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="statistics">
<?php include('inserts/_patient_entries.php'); ?>
</div>
<div class="tab-pane" id="notes-prescriptions">
<?php include('inserts/_patient_notes.php'); ?>
</div>
<div class="tab-pane" id="profile">
<?php include('inserts/_person_form.php'); ?>
</div>
</div>
/inserts/_patient_form.php
print '
<form class="form-horizontal" action="ajax/person_update.php" id="patient-form">
<input name="id" type="hidden" value="' . $person->getId() . '" required="">
<div class="control-group">
<label class="control-label">First Name</label>
<div class="controls">
<input id="first_name" name="first_name" type="text" value="' . $person->first_name . '" class="input-xlarge" required="">
</div>
</div>
<div class="control-group">
<label class="control-label">Last Name</label>
<div class="controls">
<input id="last_name" name="last_name" type="text" value="' . $person->last_name . '" class="input-xlarge" required="">
</div>
</div>
<div class="control-group">
<label class="control-label">Email</label>
<div class="controls">
<input id="email" name="email" type="text" value="' . $person->email . '" class="input-xlarge" required="">
</div>
</div>
<div class="control-group">
<label class="control-label">Phone</label>
<div class="controls">
<input id="phone" name="phone" type="text" value="' . $person->phone . '" class="input-xlarge">
</div>
</div>
<div class="control-group">
<label class="control-label">Age</label>
<div class="controls">
<input id="age" name="age" type="text" value="' . $person->age . '" class="input-xlarge" required="">
</div>
</div>
<div class="control-group">
<label class="control-label">Address</label>
<div class="controls">
<textarea id="address" name="address" rows="5" cols="300" style="width:270px;">' . $person->address . '</textarea>
</div>
</div>
<div class="control-group">
<label class="control-label">Insurance</label>
<div class="controls">
<textarea id="insurance" name="insurance" rows="5" cols="300" style="width:270px;">' . $person->insurance . '</textarea>
</div>
</div>
<div class="control-group">
<label class="control-label">New Password</label>
<div class="controls">
<input id="password" name="password" type="password" value="" class="input-xlarge">
</div>
</div>
<div class="control-group">
<div class="controls">
<button id="singlebutton" type="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
';
?>