1313use yii \base \InvalidConfigException ;
1414use yii \data \ActiveDataProvider ;
1515use yii \db \ActiveQuery ;
16+ use yii \db \ActiveRecord ;
1617use yii \web \Response ;
1718
1819/**
2324class DataTableAction extends Action
2425{
2526 /**
26- * GET or POST
27- *
27+ * Types of request method
28+ */
29+ const REQUEST_METHOD_GET = 'GET ' ;
30+ const REQUEST_METHOD_POST = 'POST ' ;
31+
32+ /**
33+ * @see \nullref\datatable\DataTableAction::getParam
2834 * @var string
2935 */
30- public $ requestMethod = " GET " ;
36+ public $ requestMethod = self :: REQUEST_METHOD_GET ;
3137
3238 /**
3339 * @var ActiveQuery
@@ -66,20 +72,20 @@ class DataTableAction extends Action
6672 */
6773 public $ formatResponse ;
6874
75+ /**
76+ * Check if query is configured
77+ * @throws InvalidConfigException
78+ */
6979 public function init ()
7080 {
7181 if ($ this ->query === null ) {
7282 throw new InvalidConfigException (get_class ($ this ) . '::$query must be set. ' );
7383 }
7484 }
7585
76- protected function getParam ($ name , $ defaultValue = null )
77- {
78- return $ this ->requestMethod == 'GET ' ?
79- Yii::$ app ->request ->getQueryParam ($ name , $ defaultValue ) :
80- Yii::$ app ->request ->getBodyParam ($ name , $ defaultValue );
81- }
82-
86+ /**
87+ * @return array|ActiveRecord[]
88+ */
8389 public function run ()
8490 {
8591 /** @var ActiveQuery $originalQuery */
@@ -114,6 +120,19 @@ public function run()
114120 return $ this ->formatResponse ($ response );
115121 }
116122
123+ /**
124+ * Extract param from request
125+ * @param $name
126+ * @param null $defaultValue
127+ * @return mixed
128+ */
129+ protected function getParam ($ name , $ defaultValue = null )
130+ {
131+ return $ this ->requestMethod == self ::REQUEST_METHOD_GET ?
132+ Yii::$ app ->request ->getQueryParam ($ name , $ defaultValue ) :
133+ Yii::$ app ->request ->getBodyParam ($ name , $ defaultValue );
134+ }
135+
117136 /**
118137 * @param ActiveQuery $query
119138 * @param array $columns
@@ -164,7 +183,7 @@ public function applyOrder(ActiveQuery $query, $columns, $order)
164183 /**
165184 * @param ActiveQuery $query
166185 * @param array $columns
167- * @return ActiveQuery
186+ * @return array|ActiveRecord[]
168187 */
169188 public function formatData (ActiveQuery $ query , $ columns )
170189 {
@@ -177,7 +196,7 @@ public function formatData(ActiveQuery $query, $columns)
177196
178197 /**
179198 * @param array $response
180- * @return ActiveQuery
199+ * @return array|ActiveRecord[]
181200 */
182201 public function formatResponse ($ response )
183202 {
0 commit comments