Your IP : 216.73.216.79


Current Path : /var/www/html/crm/models/
Upload File :
Current File : /var/www/html/crm/models/Rider.php

<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "rider".
 *
 * @property int $id
 * @property string $name
 * @property string $phone
 * @property string $code
 */
class Rider extends \yii\db\ActiveRecord {

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return 'rider';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['name', 'phone', 'code'], 'string', 'max' => 255],
            [['name', 'phone'], 'required', 'on' => 'managerider'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'phone' => 'Contact Number',
            'code' => 'Code',
        ];
    }

    public function afterSave($insert, $changedAttributes) {
        parent::afterSave($insert, $changedAttributes);
        if ($insert) {
            $this->code = 'RIDER' . sprintf("%03d", $this->id);
            $this->save();
        }
    }

}