@@ -47,16 +47,6 @@ public function setTemplate($template)
47
47
$ this ->template = $ template ;
48
48
}
49
49
50
- public function setExtraViewParams (array $ params )
51
- {
52
- $ this ->extraViewParams = $ params ;
53
- }
54
-
55
- public function setExtraViewParam ($ name , $ param )
56
- {
57
- $ this ->extraViewParams [$ name ] = $ param ;
58
- }
59
-
60
50
public function setPageRange ($ range )
61
51
{
62
52
$ this ->pageRange = abs (intval ($ range ));
@@ -77,9 +67,13 @@ public function render($template = null, array $queryParams = array(), array $vi
77
67
}
78
68
$ data = $ this ->getPaginationData ();
79
69
$ data ['route ' ] = $ this ->route ;
80
- $ data ['alias ' ] = $ this ->alias ;
81
70
$ data ['query ' ] = array_merge ($ this ->params , $ queryParams );
82
- $ data = array_merge ($ this ->extraViewParams , $ viewParams , $ data/* cannot be broken*/ );
71
+ $ data = array_merge (
72
+ $ this ->paginatorOptions , // options given to paginator when paginated
73
+ $ this ->customParameters , // all custom parameters for view
74
+ $ viewParams , // additional custom parameters for view
75
+ $ data // merging base route parameters last, to avoid broke of integrity
76
+ );
83
77
return $ this ->engine ->render ($ this ->template , $ data );
84
78
}
85
79
@@ -105,11 +99,15 @@ public function sortable($title, $key, $options = array(), $params = array(), $t
105
99
), $ options );
106
100
107
101
$ params = array_merge ($ this ->params , $ params );
108
- $ direction = isset ($ options [$ this ->alias .'direction ' ]) ? $ options [$ this ->alias .'direction ' ] : 'asc ' ;
102
+ $ direction = isset ($ options [$ this ->getPaginatorOption ('sortDirectionParameterName ' )]) ?
103
+ $ options [$ this ->getPaginatorOption ('sortDirectionParameterName ' )] : 'asc '
104
+ ;
109
105
110
- $ sorted = isset ($ params [$ this ->alias .'sort ' ]) && $ params [$ this ->alias .'sort ' ] == $ key ;
106
+ $ sorted = isset ($ params [$ this ->getPaginatorOption ('sortFieldParameterName ' )])
107
+ && $ params [$ this ->getPaginatorOption ('sortFieldParameterName ' )] == $ key
108
+ ;
111
109
if ($ sorted ) {
112
- $ direction = $ params [$ this ->alias . ' direction ' ];
110
+ $ direction = $ params [$ this ->getPaginatorOption ( ' sortDirectionParameterName ' ) ];
113
111
$ direction = (strtolower ($ direction ) == 'asc ' ) ? 'desc ' : 'asc ' ;
114
112
$ class = $ direction == 'asc ' ? 'desc ' : 'asc ' ;
115
113
if (isset ($ options ['class ' ])) {
@@ -125,7 +123,11 @@ public function sortable($title, $key, $options = array(), $params = array(), $t
125
123
}
126
124
$ params = array_merge (
127
125
$ params ,
128
- array ($ this ->alias .'sort ' => $ key , $ this ->alias .'direction ' => $ direction , $ this ->alias .'page ' => 1 )
126
+ array (
127
+ $ this ->getPaginatorOption ('sortFieldParameterName ' ) => $ key ,
128
+ $ this ->getPaginatorOption ('sortDirectionParameterName ' ) => $ direction ,
129
+ $ this ->getPaginatorOption ('pageParameterName ' ) => 1 // reset to 1 on sort
130
+ )
129
131
);
130
132
131
133
$ options ['href ' ] = $ this ->routerHelper ->generate ($ this ->route , $ params , $ options ['absolute ' ]);
@@ -140,9 +142,11 @@ public function sortable($title, $key, $options = array(), $params = array(), $t
140
142
$ this ->sortableTemplate = $ template ;
141
143
}
142
144
143
- $ alias = $ this ->alias ;
144
-
145
- return $ this ->engine ->render ($ this ->sortableTemplate , compact ('options ' , 'title ' , 'direction ' , 'sorted ' , 'key ' , 'alias ' ));
145
+ return $ this ->engine ->render ($ this ->sortableTemplate , array_merge (
146
+ $ this ->paginatorOptions ,
147
+ $ this ->customParameters ,
148
+ compact ('options ' , 'title ' , 'direction ' , 'sorted ' , 'key ' )
149
+ ));
146
150
}
147
151
148
152
public function getPaginationData ()
0 commit comments