2

我对 php phalcon 和语言本身相当陌生。我正在制作一个涉及抽象类和派生类的网站。

抽象类:

<?php

abstract class UsersAbstract extends \Phalcon\Mvc\Model {

    private $Full_Name; //
    private $Mobile_Number; //
    private $Email_ID; //
    private $City; //
    private $Country;  //
    private $DoB; //
    private $Gender; //
    private $Age; //
    private $Availability_Flag;   /*value of flag is 1 for active and 0 for inactive*/


    /********setters and getters for all data members which I have not written here*******/


    public function getSource()
    {
        return 'users_abstract';
    }
} 

派生类

<?php
class UserPatients extends UsersAbstract
{
    private $Patient_ID;
    private $Guardian_Name;
    private $Doctors = array();

    public function getSource()
    {
        return 'user_patients';
    }

    /***************setter and getter for patient id*******************/
    public function getPatientID()
    {
        return $this->Patient_ID;
    }
    public function setPatientID($value)
    {
        $this->Patient_ID = $value;
    }

    /****************setter and getter for guardian name******************/
    public function getGuardianName()
    {
        return $this->Guardian_Name;
    }
public function setGuardianName($value)
{
    $this->Guardian_Name = $value;
}

/****************getter and setter for doctor array*********************/
public function getDoctors()
{
    return $this->Doctors;
}

public function setDoctors($value)
{
    $this->Doctors = $value;
}} 

在我的控制器中,我正在从视图中的表单中读取数据。声明了 UserPatients 类的对象并设置了它的数据成员。这是我在控制器 PatientSignInController 中调用的操作方法:

public function SaveAction()
    {
       if (!empty($_POST)){
            $patient_data = new UserPatients();
            $patient_data->setFull_Name($_POST['Full_Name']);
            $patient_data->setGuardianName($_POST['Guardian_Name']);
            $patient_data->setDoB($_POST['DoB']);
            $patient_data->setAge($_POST['Age']);
            $patient_data->setGender($_POST['gender']);
            $patient_data->setMobile_Number($_POST['Contact_No']);
            $patient_data->setEmail_Address($_POST['Email_ID']);
            $patient_data->setCity($_POST['City']);
            $patient_data->setCountry($_POST['Country']);
            $patient_data->setPatientID($_POST['Patients_ID']);
            $patient_data->setFlag(1);

            $doctorsArray = array("ACD","ABC"); //some hard coded values for the time being
            $patient_data->setDoctors($doctorsArray);

            $patient_medical_info = new PatientInfo();

            $patient_medical_info->setBP($_POST['BP']);
            $patient_medical_info->setTemperature($_POST['Temperature']);
            $patient_medical_info->setInformation($_POST['Info']);
            $patient_medical_info->setPatientID($_POST['Patients_ID']);
            $patient_medical_info->setDateOfMeeting(date("d/m/y"));

           $patient_data->save();
           $patient_medical_info->save();


          $this->response->redirect("../../../../WebMCare/PatientSignIn/Index");

       }
    }

我的数据库的结构与这些类相同 - 我有一个Users_Abstract包含抽象类所有属性的表,我有一个User_Patients包含子类所有属性的表。

当我在视图中点击表单上的保存按钮并检查数据库表时,我发现新条目已添加到patient_info表中。这意味着它$patient_medical_info->save()正在工作。

但是,该表users_abstract不包含相应对象的任何新数据,而该表user_patients确实获取了关联数据。我检查了保存方法中的错误消息,但它什么也没返回。我似乎无法在网上找到任何东西。请帮我。

我尝试通过将具有所有 12 个属性的一个表与类UsersAbstractUser_Patients. 即使这样也行不通。

4

0 回答 0