| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace addons\StarChain\common\models;
- use Yii;
- /**
- * This is the model class for table "{{%addons_star_chain_category}}".
- *
- * @property int $id
- * @property int|null $category_id 分类ID
- * @property int|null $pid
- * @property string|null $name 分类名称
- * @property int|null $sort 排序
- * @property int|null $level 分类层级,从0开始
- * @property int|null $created_at
- * @property int|null $updated_at
- */
- class Category extends BaseModel
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_star_chain_category}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['sort', 'level', 'created_at', 'updated_at'], 'integer'],
- [['category_id', 'pid'], 'max' => 64],
- [['name'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'category_id' => 'Category ID',
- 'pid' => 'Pid',
- 'name' => 'Name',
- 'sort' => 'Sort',
- 'level' => 'Level',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
-
- /**
- * 获取分类名称
- *
- * @param string $category_id
- * @return string
- */
- public static function getCategoryName($category_id)
- {
- return self::find()->where(compact('category_id'))->select('name')->scalar();
- }
- }
|