Sorry for the late reply. Here is my code:
<?php
/**
* This is the model class for table "employee".
*
* The followings are the available columns in table 'employee':
* @property integer $id
* @property string $fname
* @property string $lname
* @property string $minitial
* @property string $address
* @property string $dob
* @property string $mobile
* @property string $landline
* @property string $email
* @property string $gender
* @property string $civilStatus
* @property string $religion
* @property string $marriageDate
* @property string $dateHired
* @property string $sssId
* @property string $tinId
*
* The followings are the available model relations:
* @property Attachment[] $attachments
* @property Dependent[] $dependents
* @property EmpBenefit[] $empBenefits
* @property Hds[] $hds
* @property HubEmployee[] $hubEmployees
* @property PayHeader[] $payHeaders
* @property Staff[] $staffs
*/
class Employee extends CActiveRecord
{
public $active, $dateUpdate;
public $jobtitle, $date_positioned, $rate;
const GENDER_MALE='Male';
const GENDER_FEMALE='Female';
const CIVIL_SINGLE='Single';
const CIVIL_MARRIED='Married';
const CIVIL_WIDOWED='Widowed';
const CIVIL_SEPARATED='Separated';
public function getGenderOptions()
{
return array(
self::GENDER_MALE=>'Male',
self::GENDER_FEMALE=>'Female',
);
}
public function getCivilOptions()
{
return array(
self::CIVIL_SINGLE=>'Single',
self::CIVIL_MARRIED=>'Married',
self::CIVIL_WIDOWED=>'Widowed',
self::CIVIL_SEPARATED=>'Separated',
);
}
/**
* Returns the static model of the specified AR class.
* @return Employee the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'employee';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('fname, lname, minitial, address, dob, mobile, landline, email, gender, civilStatus, religion, dateHired, sssId, tinId', 'required'),
array('fname, lname, email, religion, sssId, tinId', 'length', 'max'=>45),
array('email', 'email'),
array('minitial', 'length', 'max'=>2),
array('address', 'length', 'max'=>100),
array('mobile', 'length', 'max'=>20),
array('landline, civilStatus', 'length', 'max'=>15),
array('gender', 'length', 'max'=>6),
array('marriageDate', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, fname, lname, minitial, address, dob, mobile, landline, email, gender, civilStatus, religion, marriageDate, dateHired, sssId, tinId', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'attachments' => array(self::HAS_MANY, 'Attachment', 'employee_id'),
'dependents' => array(self::HAS_MANY, 'Dependent', 'employee_id'),
'empBenefits' => array(self::HAS_MANY, 'EmpBenefit', 'employee_id'),
'hds' => array(self::HAS_MANY, 'Hds', 'employee_id'),
'hubEmployees' => array(self::HAS_MANY, 'HubEmployee', 'employee_id'),
'payHeaders' => array(self::HAS_MANY, 'PayHeader', 'employee_id'),
'staffs' => array(self::HAS_MANY, 'Staff', 'employee_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'fname' => 'First Name',
'lname' => 'Last Name',
'minitial' => 'Middle Initial',
'address' => 'Address',
'dob' => 'Date of Birth',
'mobile' => 'Mobile',
'landline' => 'Landline',
'email' => 'Email',
'gender' => 'Gender',
'civilStatus' => 'Civil Status',
'religion' => 'Religion',
'marriageDate' => 'Marriage Date',
'dateHired' => 'Date Hired',
'sssId' => 'SSS',
'tinId' => 'TIN',
'staffposition' => 'Staff Position',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function searchHds()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('hds');
$criteria->compare('id',$this->id);
$criteria->compare('fname',$this->fname,true);
$criteria->compare('lname',$this->lname,true);
$criteria->compare('minitial',$this->minitial,true);
$criteria->compare('address',$this->address,true);
$criteria->compare('dob',$this->dob,true);
$criteria->compare('mobile',$this->mobile,true);
$criteria->compare('landline',$this->landline,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('gender',$this->gender,true);
$criteria->compare('civilStatus',$this->civilStatus,true);
$criteria->compare('religion',$this->religion,true);
$criteria->compare('marriageDate',$this->marriageDate,true);
$criteria->compare('dateHired',$this->dateHired,true);
$criteria->compare('sssId',$this->sssId,true);
$criteria->compare('tinId',$this->tinId,true);
$criteria->compare('hds.active',$this->active,true);
$criteria->compare('hds.dateUpdate',$this->dateUpdate,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public function searchStaff()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('staffs');
$criteria->compare('id',$this->id);
$criteria->compare('fname',$this->fname,true);
$criteria->compare('lname',$this->lname,true);
$criteria->compare('minitial',$this->minitial,true);
$criteria->compare('address',$this->address,true);
$criteria->compare('dob',$this->dob,true);
$criteria->compare('mobile',$this->mobile,true);
$criteria->compare('landline',$this->landline,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('gender',$this->gender,true);
$criteria->compare('civilStatus',$this->civilStatus,true);
$criteria->compare('religion',$this->religion,true);
$criteria->compare('marriageDate',$this->marriageDate,true);
$criteria->compare('dateHired',$this->dateHired,true);
$criteria->compare('sssId',$this->sssId,true);
$criteria->compare('tinId',$this->tinId,true);
$criteria->compare('staffs.jobtitle',$this->jobtitle,true);
$criteria->compare('staffs.date_positioned',$this->date_positioned,true);
$criteria->compare('staffs.rate',$this->rate,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
//Employee Controller
....
public function actionAdmin()
{
$type = $_GET['type'];
if ($type == 'Hds'){
$admin = 'adminHds';
$employee = new Employee('searchHds');
$typeModel = new Hds('search');
}
else if ($type == 'Staff'){
$admin = 'adminStaff';
$employee = new Employee('searchStaff');
$typeModel = new Staff('search');
}
$employee->unsetAttributes(); // clear any default values
$typeModel->unsetAttributes();
if(isset($_GET['Employee']))
$employee->attributes=$_GET['Employee'];
$this->render($admin,array(
'employee'=>$employee,
'type'=>$type,
'typeModel'=>$typeModel
));
}
...