The point is i cannot use my active record relation, even i have defined the relation. The following is my User Active Record Model.
<?php
/**
* This is the model class for table "skat_user".
*
* The followings are the available columns in table 'skat_user':
* @property integer $id
* @property string $name
* @property string $username
* @property string $password
* @property string $role
* @property integer $skat_port_id
*
* The followings are the available model relations:
* @property Port $skatPort
* @property UserLog[] $userLogs
*/
class User extends SkatTwoActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return User 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 'skat_user';
}
/**
* @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('username, password, role', 'required'),
array('skat_port_id', 'numerical', 'integerOnly'=>true),
array('name, username, password', 'length', 'max'=>128),
array('role', 'length', 'max'=>15),
array('crated_time, modified_time', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, name, username, password, role, skat_port_id, crated_time, modified_time', '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(
'skatPort' => array(self::BELONGS_TO, 'Port', 'skat_port_id'),
'userLogs' => array(self::HAS_MANY, 'UserLog', 'skat_user_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'name' => 'Nama',
'username' => 'Username',
'password' => 'Password',
'role' => 'Level',
'skat_port_id' => 'Pelabuhan',
'created_time'=>'Waktu Pembuatan',
'modified_time'=>'Waktu Perubahan',
);
}
/**
* 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 search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('name',$this->name,true);
$criteria->compare('username',$this->username,true);
$criteria->compare('password',$this->password,true);
$criteria->compare('role',$this->role,true);
$criteria->compare('skat_port_id',$this->skat_port_id);
$criteria->compare('created_time',$this->name);
$criteria->compare('modified_time',$this->name);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* Perform one-way encryption on the password before we restore it in the database
*/
protected function afterValidate()
{
parent::afterValidate();
$this->password=$this->encrypt($this->password);
}
public function encrypt($value)
{
return md5($value);
}
/**
* @return array of port for this user, indexed by port IDs
*/
public function getPortOptions()
{
$port = CHtml::listData(Port::model()->findAll(), 'id', 'name');
return $port;
}
/**
* Perform fetching all data from the model
* @return array of all model attribute from the model
*/
public function getAll()
{
$data = self::model()->findAll();
$result[0] = "";
foreach($data as $element){
$result[$element->id] = $element->username . " (" . $element->role . " - " . $element->skatPort->name . ")";
}
return $result;
}
/**
* Perform assertion of admin, call in component webUser
* @return boolean
*/
public function isAdmin()
{
return $this->role == 'admin';
}
/**
* Perform assertion of operator_pusat, call in component webUser
* @return boolean
*/
public function isOperatorPusat()
{
return $this->role == 'operator_pusat';
}
/**
* Perform assertion of operator_daerah, call in component webUser
* @return boolean
*/
public function isOperatorDaerah()
{
return $this->role == 'operator_daerah';
}
}
Could you help me please?