Created
March 17, 2018 11:17
-
-
Save calcio/ecbc94f98246ba069bd5ae52203e6143 to your computer and use it in GitHub Desktop.
Model Category Admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\modules\admin\models; | |
use Yii; | |
use yii\behaviors\TimestampBehavior; | |
/** | |
* This is the model class for table "categories". | |
* | |
* @property integer $id | |
* @property string $name | |
* @property integer $status | |
* @property integer $created_at | |
* @property integer $updated_at | |
* | |
* @property Products[] $products | |
*/ | |
class Category extends yii\db\ActiveRecord | |
{ | |
CONST STATUS_ACTIVE = 1; | |
CONST STATUS_INACTIVE = 0; | |
CONST STATUS_ACTIVE_STRING = 'Active'; | |
CONST STATUS_INACTIVE_STRING = 'Inactive'; | |
/** | |
* @inheritdoc | |
*/ | |
public static function tableName() | |
{ | |
return '{{%categories}}'; | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function rules() | |
{ | |
return [ | |
[['name', 'status'], 'required'], | |
[['status'], 'integer'], | |
[['name'], 'string', 'max' => 80], | |
[['name'], 'unique'], | |
]; | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function attributeLabels() | |
{ | |
return [ | |
'id' => Yii::t('app', 'ID'), | |
'name' => Yii::t('app', 'Name'), | |
'status' => Yii::t('app', 'Status'), | |
'created_at' => Yii::t('app', 'Created At'), | |
'updated_at' => Yii::t('app', 'Updated At'), | |
]; | |
} | |
public function behaviors() | |
{ | |
return [ | |
[ | |
'class' => TimestampBehavior::className(), | |
], | |
]; | |
} | |
public function getStatusItems() | |
{ | |
return [ | |
self::STATUS_INACTIVE => self::STATUS_INACTIVE_STRING, | |
self::STATUS_ACTIVE => self::STATUS_ACTIVE_STRING, | |
]; | |
} | |
/** | |
* @return \yii\db\ActiveQuery | |
*/ | |
public function getProducts() | |
{ | |
return $this->hasMany(Product::className(), ['category_id' => 'id']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment