-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodes.php
75 lines (63 loc) · 1.66 KB
/
Nodes.php
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
<?php
namespace backend\models;
use Yii;
use yii\data\ActiveDataProvider;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
class Nodes extends ActiveRecord
{
public static function tableName()
{
return "node";
}
public function behaviors()
{
return [
TimestampBehavior::className(),
];
}
public function rules()
{
return [
[["url", "msg", "pid"], "required"],
["url", "string", "max" => 20],
["url", "unique", "targetClass" => 'backend\models\Nodes', "message" => "该路由已存在", "filter" => function($model) {
if ($this->url == "#") {
$model->where("0 = 1");
}
}],
["msg", "string", "max" => 100],
["pid", "number", ],
["is_show", "number", ],
["is_show", "default" , "value" => 1],
];
}
public function search()
{
$dataProvider = new ActiveDataProvider([
"query" => static::find()
]);
return $dataProvider;
}
public function add()
{
return $this->save(false);
}
public function edit()
{
return $this->save(false);
}
public function getPidArr()
{
//$ids = static::find()->select(["id", "msg"])->indexBy("id")->all();
$ids = static::find()->select(["id", "msg"])->where(["pid" => 0])->all();
$res = [];
$res[null] = "请选择";
$res[0] = "顶级分类";
foreach ($ids as $k => $v) {
$id = $v["id"];
$res[$id] = $v["msg"];
}
return $res;
}
}