Derived Classes in Php Phalcon

143 Views Asked by At

I am fairly new to php phalcon and the language itself. I am making a website that involves an abstract class and derived classes.

The Abstract Class:

<?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';
    }
} 

The derived class

<?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;
}} 

In my controller, I am reading data from a form in a view. An object of the class UserPatients is declared and its data members are set. Here is the action method that I am calling in the controller 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");

       }
    }

The structure of my database is the same as these classes - I have a table Users_Abstract with all the attributes of the abstract class and I have a table User_Patients with all the attributes of the child class.

When I hit the save button on the form in the view and check the database tables, I discover that the new entries are added in the patient_info table. Which means that the $patient_medical_info->save() is working.

However, the table users_abstract does not contain any new data for the corresponding object, while the table user_patients does get the associated data. I checked messages for errors in save method, but it returned nothing. I can't seem to find anything online. Please help me.

I have tried storing data in a single table by associating one table, with all 12 attributes, to the classes UsersAbstract and User_Patients. Even that does not work.

0

There are 0 best solutions below