Skip to content

Commit 29d97aa

Browse files
committed
no data and model in widget
1 parent 720d4c4 commit 29d97aa

File tree

4 files changed

+41
-44
lines changed

4 files changed

+41
-44
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ composer require pceuropa/yii2-sort
1010
##Configure
1111
```
1212
<php
13-
1413
use pceuropa\sort\SortWidget;
1514
?>
1615
1716
<?= SortWidget::widget([
18-
'image_url' => '',
19-
'table' => '',
17+
'image_url' => '', // example Url::to('@www', 'http'),
18+
'data' => $model::find()->orderBy(['serialize' => SORT_ASC])->all(),
2019
]) ?>
2120
2221
```

SortWidget.php

+31-24
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,46 @@
22
namespace pceuropa\sort;
33

44
use Yii;
5-
65
class SortWidget extends \yii\base\Widget{
76

8-
public $model;
9-
public $image_url;
10-
public $table;
7+
public $config;
8+
public $image_url;
9+
public $data;
10+
public $table;
1111

12-
public function init(){
13-
parent::init();
14-
if ($this->image_url === null){
15-
$this->image_url = '/images/';
12+
public function init(){
13+
parent::init();
14+
15+
if ($this->image_url === null){
16+
$this->image_url = '/images/';
17+
}
18+
19+
if ($this->data === null){
20+
$this->data = [
21+
['id' => 1, 'name' => 'no data', 'url' => '', 'image' => ''],
22+
['id' => 2, 'name' => 'default data', 'url' => '', 'image' => '']
23+
];
24+
}
25+
26+
$this->config = [
27+
'image_url' => $this->image_url
28+
];
1629
}
17-
}
18-
1930

20-
public function run(){
21-
return $this->sort();
22-
}
31+
public function run(){
32+
return $this->renderWidget();
33+
}
2334

24-
public function sort(){
35+
public function renderWidget(){
2536

26-
return $this->render('sort' , ['list' => self::findAllAsArray(), 'config' => ['image_url' => $this->image_url]]);
37+
return $this->render('sort' , ['list' => $this->data, 'config' => $this->config]);
2738

28-
}
39+
}
2940

30-
public function findAllAsArray(){
41+
public function findAll(){
3142

32-
$array = Yii::$app->db->createCommand('SELECT * FROM banners_footer ORDER BY `serialize` ASC')
33-
->bindValue(':table', 'banners_footer')
34-
->queryAll();
35-
return $array;
36-
}
37-
38-
43+
$array = Yii::$app->db->createCommand('SELECT * FROM '.$table.' ORDER BY `serialize` ASC')->queryAll();
44+
return $array;
45+
}
3946

4047
}

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"sort",
99
"drag and drop"
1010
],
11-
"version": "1.0.3",
11+
"version": "1.0.4",
1212
"homepage": "https://github.com/pceuropa/yii2-sorting-items",
1313
"type": "yii2-extension",
1414
"license": "MIT",

views/sort.php

+7-16
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,17 @@
3333

3434

3535
$this->registerCss("
36-
#baners_scrolls ul { margin: 0; padding: 0; list-style-type: none; }
37-
#baners_scrolls ul li{ padding: 5px; border:solid 1px #ccc; cursor:grab;}
38-
#baners_scrolls ul li:hover { border:solid 1px #5CB85C;}
39-
40-
#baners_scrolls ul li img{ max-height:75px; }
41-
42-
#baners_scrolls .big {
43-
font-size:200%;
44-
color:#eee;
45-
margin-top:25px;
46-
}
36+
#baners_scrolls ul { margin: 0; padding: 0; list-style-type: none}
37+
#baners_scrolls ul li{ padding: 5px; border:solid 1px #ccc; cursor:grab}
38+
#baners_scrolls ul li:hover { border:solid 1px #5CB85C}
39+
#baners_scrolls ul li img{ max-height:75px}
40+
#baners_scrolls .big {font-size:200%; color:#eee; margin-top:25px}
4741
#baners_scrolls .edit-icon a span { margin-top:15px}
4842
#baners_scrolls .edit-icon a span.glyphicon-trash { color: #D75555}
49-
50-
}");
43+
");
5144

5245
$this->registerJs('var config = {
53-
group: "nav",
46+
group: "pclista",
5447
animation: 0,
5548
ghostClass: "ghost",
5649
onUpdate: function () {
@@ -70,8 +63,6 @@
7063
alert(textStatus);
7164
}
7265
});
73-
74-
7566
},
7667
}
7768
Sortable.create(lista, config);', 3);

0 commit comments

Comments
 (0)