-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathLookup.php
More file actions
79 lines (66 loc) · 1.57 KB
/
Lookup.php
File metadata and controls
79 lines (66 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "tbl_lookup".
*
* @property integer $id
* @property string $name
* @property integer $code
* @property string $type
* @property integer $position
*/
class Lookup extends \yii\db\ActiveRecord
{
private static $_items=array();
/**
* @inheritdoc
*/
public static function tableName()
{
return 'tbl_lookup';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name', 'code', 'type', 'position'], 'required'],
[['code', 'position'], 'integer'],
[['name', 'type'], 'string', 'max' => 128]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => '名字',
'code' => '代码',
'type' => '分类',
'position' => '排序',
];
}
public static function items($type)
{
if(!isset(self::$_items[$type]))
self::loadItems($type);
return self::$_items[$type];
}
public static function item($type,$code)
{
if(!isset(self::$_items[$type]))
self::loadItems($type);
return isset(self::$_items[$type][$code]) ? self::$_items[$type][$code] : false;
}
private static function loadItems($type)
{
self::$_items[$type]=array();
$models=self::findAll(['type' => $type]);
foreach($models as $model)
self::$_items[$type][$model->code]=$model->name;
}
}