diff --git a/README.md b/README.md index 2c0009e..345d684 100644 --- a/README.md +++ b/README.md @@ -43,12 +43,18 @@ To access the module, you need to configure the modules array in your applicatio 'modules' => [ 'settings' => [ 'class' => 'yii2mod\settings\Module', - // Some controller properties maybe need to change. + // Also you can override some controller properties in following way: 'controllerMap' => [ 'default' => [ 'class' => 'yii2mod\settings\controllers\DefaultController', + 'searchClass' => [ + 'class' => 'yii2mod\settings\models\search\SettingSearch', + 'pageSize' => 25 + ], + 'modelClass' => 'Your own cms model class', 'indexView' => 'custom path to index view file', - 'settingSearchClass' => 'Your own search model class' + 'createView' => 'custom path to create view file', + 'updateView' => 'custom path to update view file', ] ] ], diff --git a/controllers/DefaultController.php b/controllers/DefaultController.php index 8fc7050..6999771 100644 --- a/controllers/DefaultController.php +++ b/controllers/DefaultController.php @@ -31,14 +31,14 @@ class DefaultController extends Controller public $updateView = '@vendor/yii2mod/yii2-settings/views/default/update'; /** - * @var string search class name for settings search + * @var string search class name for searching */ - public $settingSearchClass = 'yii2mod\settings\models\search\SettingSearch'; + public $searchClass = 'yii2mod\settings\models\search\SettingSearch'; /** - * @var string settings model class name for CRUD operations + * @var string model class name for CRUD operations */ - public $settingModelClass = 'yii2mod\settings\models\SettingModel'; + public $modelClass = 'yii2mod\settings\models\SettingModel'; /** * Returns a list of behaviors that this component should behave as. @@ -83,7 +83,7 @@ public function actions() */ public function actionIndex() { - $searchModel = Yii::createObject($this->settingSearchClass); + $searchModel = Yii::createObject($this->searchClass); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render($this->indexView, [ @@ -101,7 +101,7 @@ public function actionIndex() */ public function actionCreate() { - $model = Yii::createObject($this->settingModelClass); + $model = Yii::createObject($this->modelClass); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', Yii::t('yii2mod.settings', 'Setting has been created.')); @@ -162,7 +162,7 @@ public function actionDelete($id) */ protected function findModel($id) { - $settingModelClass = $this->settingModelClass; + $settingModelClass = $this->modelClass; if (($model = $settingModelClass::findOne($id)) !== null) { return $model; diff --git a/models/search/SettingSearch.php b/models/search/SettingSearch.php index e7dde0e..266b64c 100644 --- a/models/search/SettingSearch.php +++ b/models/search/SettingSearch.php @@ -11,6 +11,11 @@ */ class SettingSearch extends SettingModel { + /** + * @var int the default page size. + */ + public $pageSize = 10; + /** * @inheritdoc */ @@ -35,7 +40,7 @@ public function search($params) $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ - 'pageSize' => 10 + 'pageSize' => $this->pageSize ] ]);