我正在创建一个医院管理系统的网站。我有一个患者控制器和一个医疗报告控制器。每位患者都有"查看报告"的行动。当用户点击查看报告时,应该将他/她定向到医疗报告,并且仅显示与患者控制器中的Patient_id相关的那个字段。我该怎么做呢?
患者表:
<?php
namespace App\Model\Table;
use Search\Manager;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class PatientsTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('patients');
$this->displayField('Patient_ID');
$this->primaryKey('Patient_ID');
$this->addBehavior('Search.Search');
$this->searchManager()
->value('Patient_ID');
}
public function validationDefault(Validator $validator)
{
$validator
->allowEmpty('Patient_ID', 'create');
$validator
->requirePresence('Name', 'create')
->notEmpty('Name');
$validator
->requirePresence('Address', 'create')
->notEmpty('Address');
$validator
->date('DOB')
->requirePresence('DOB', 'create')
->notEmpty('DOB');
$validator
->allowEmpty('Contact');
$validator
->requirePresence('Gender', 'create')
->notEmpty('Gender');
$validator
->allowEmpty('Blood_Group');
return $validator;
}
}
医疗报告表:
<?php
namespace App\Model\Table;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class MedicalReportTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('medical_report');
$this->displayField('Report_No');
$this->primaryKey('Report_No');
}
public function validationDefault(Validator $validator)
{
$validator
->requirePresence('Patient_ID', 'create')
->notEmpty('Patient_ID');
$validator
->requirePresence('Report_No', 'create');
$validator
->date('R_date')
->requirePresence('R_date', 'create')
->notEmpty('R_date');
$validator
->date('C_date')
->requirePresence('C_date');
$validator
->requirePresence('Room_No');
$validator
->allowEmpty('Diet');
$validator
->numeric('Payment')
->requirePresence('Payment');
return $validator;
}
}
答案 0 :(得分:0)
您可以使用CakePHP的HtmlHelper创建一个URL来查看医疗报告,如下所示:
<?php
echo $this->Html->link(
'View Report',
['controller' => 'MedicalReports', 'action' => 'view', $MedicalReport->id],
['class' => 'button', 'target' => '_blank']);
这会产生类似:<a href="/medical-reports/view/123" class="button" target="_blank">View Report</a>
创建HTML链接的通用方法。使用$ options来 指定元素的属性以及是否为$ title 应该逃脱。
<强> MedicalReportsController.php 强>
在您的控制器中,您可以创建view()
函数来定义action的代码。
<?php // src/Controller/MedicalReportsController.php
class MedicalReportsController extends AppController {
public function view($id)
{
// Fetch the medical report from the database based on ID
$medicalReport = $this->MedicalReports->get($id);
// Pass it along to the view
$this->set('medical_report',$medicalReport);
} }
set()
函数将数据从Controller发送到View。
Controller::set()
方法是从您发送数据的主要方式 控制器到你的视野。