init
This commit is contained in:
81
models/Vehicle.php
Normal file
81
models/Vehicle.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "vehicle".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $plate
|
||||
* @property string $type
|
||||
* @property string $company
|
||||
* @property string $vehicle_type
|
||||
* @property string $driver
|
||||
* @property string $telephone
|
||||
* @property string $indentity_card
|
||||
* @property int $created_at
|
||||
* @property int $modified_at
|
||||
*/
|
||||
class Vehicle extends \yii\db\ActiveRecord {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName() {
|
||||
return 'vehicle';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules() {
|
||||
return [
|
||||
[['plate', 'type'], 'required'],
|
||||
[['company', 'vehicle_type'], 'string'],
|
||||
[['plate', 'type'], 'string', 'max' => 20],
|
||||
[['driver', 'telephone', 'indentity_card'], 'string', 'max' => 200],
|
||||
[['created_at', 'modified_at'], 'integer']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels() {
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'plate' => 'Biển số xe',
|
||||
'type' => 'Loại xe',
|
||||
'company' => 'Tên công ty',
|
||||
'vehicle_type' => 'Kiểu xe',
|
||||
'driver' => 'Lái xe',
|
||||
'telephone' => 'Điện thoại',
|
||||
'indentity_card' => 'CMT',
|
||||
];
|
||||
}
|
||||
|
||||
public function create($data) {
|
||||
$r = $this->load([
|
||||
'plate' => $data['plate'],
|
||||
'type' => $data['type'],
|
||||
'company' => $data['company'],
|
||||
'vehicle_type' => $data['vehicle_type'],
|
||||
'driver' => $data['driver'],
|
||||
'telephone' => $data['telephone'],
|
||||
'indentity_card' => $data['indentity_card'],
|
||||
'created_at' => time(),
|
||||
'modified_at' => time()
|
||||
], '');
|
||||
if ($r) {
|
||||
try {
|
||||
$this->save();
|
||||
return $this->id;
|
||||
} catch (\Exception $ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user