/** * Initializes the module. * * This method is called after the module is created and initialized with property values * given in configuration. The default implementation will initialize [[controllerNamespace]] * if it is not set. * * If you override this method, please make sure you call the parent implementation. * @throws InvalidParamException */ public function init() { parent::init(); if (!is_dir(Yii::getAlias($this->uploadFolder))) { mkdir(Yii::getAlias($this->uploadFolder), 0777, true); } }
/** * @inheritdoc */ public function behaviors() { $behaviors = ['verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['POST']]], 'access' => ['class' => AccessControl::className(), 'rules' => [['allow' => true, 'roles' => ['@']]]]]; if (Module::hasUserRole()) { if (Module::hasMultiLanguage()) { return ArrayHelper::merge($behaviors, ['role' => ['class' => RoleFilter::className(), 'name' => Translate::setting(), 'actions' => ['index' => Translate::index(), 'create' => Translate::create(), 'update' => Translate::update(), 'delete' => Translate::delete()]]]); } else { return ArrayHelper::merge($behaviors, ['role' => ['class' => RoleFilter::className(), 'name' => 'Setting', 'actions' => ['index' => Yii::t('setting', 'List'), 'create' => Yii::t('setting', 'Create'), 'update' => Yii::t('setting', 'Update'), 'delete' => Yii::t('setting', 'Delete')]]]); } } else { return $behaviors; } }
/** * {@inheritDoc} */ public function rules() { $rules = parent::rules(); return ArrayHelper::merge($rules, ['backendLoginValidate' => ['login', function ($attribute) { if ($this->user !== null && $this->user->getRole()->exists() && ($role = $this->user->getRole()->one())) { /** @var $role Role */ if ($role->is_backend_login == 0) { if (Module::hasMultiLanguage()) { $this->addError($attribute, RoleHelper::translate('invalid_login_or_password')); } else { $this->addError($attribute, Yii::t('role', 'Invalid login or password')); } } } }]]); }
public function beforeAction(ActionEvent $event) { $controller = $event->action->controller->className(); $action = $event->action->id; if (RoleChecker::isAuth($controller, $action)) { return true; } else { if (Yii::$app->user->isGuest) { Yii::$app->user->loginRequired(); } else { if (Module::hasMultiLanguage()) { throw new ForbiddenHttpException(RoleHelper::translate('forbidden'), 403); } else { throw new ForbiddenHttpException(Yii::t('role', 'You are not allowed to perform this action.'), 403); } } } }
public function init() { parent::init(); }
<?php /* @var $this yii\web\View */ use navatech\base\Module; use navatech\role\helpers\RoleHelper; use yii\bootstrap\Html; /* @var $model navatech\role\models\Role */ $this->title = Module::hasMultiLanguage() ? RoleHelper::translate('update') . ' ' . $model->name : Yii::t('role', 'Update: {0}', $model->name); $this->params['breadcrumbs'][] = ['label' => Module::hasMultiLanguage() ? RoleHelper::translate('user_role') : Yii::t('role', 'User role'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = Module::hasMultiLanguage() ? RoleHelper::translate('update') : Yii::t('role', 'Update'); ?> <div class="role-update"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php echo $this->render('_form', ['model' => $model]); ?> </div>
<?php /* @var $this yii\web\View */ use navatech\base\Module; use navatech\role\helpers\RoleHelper; use yii\bootstrap\Html; /* @var $model navatech\role\models\Role */ $this->title = Module::hasMultiLanguage() ? RoleHelper::translate('create') : Yii::t('role', 'Create'); $this->params['breadcrumbs'][] = ['label' => Module::hasMultiLanguage() ? RoleHelper::translate('user_role') : Yii::t('role', 'User role'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="role-create"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php echo $this->render('_form', ['model' => $model]); ?> </div>
</div> <?php } ?> </div> </div> <?php } ?> <?php } ?> </div> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Module::hasMultiLanguage() ? RoleHelper::translate('create') : Yii::t('role', 'Create') : (Module::hasMultiLanguage() ? RoleHelper::translate('update') : Yii::t('role', 'Update')), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div> </div> <script> $(document).on("click", "input[name='checkall']", function() { var th = $(this); if(th.is(":checked")) { th.closest(".row").find(".checkbox-list").find("input[type='checkbox']").prop("checked", true); } else { th.closest(".row").find(".checkbox-list").find("input[type='checkbox']").prop("checked", false); }
/** * @inheritdoc */ public function init() { if ($this->languages == null) { if (Module::hasMultiLanguage()) { $languages = \navatech\language\helpers\MultiLanguageHelper::getLanguages(); foreach ($languages as $language) { $this->languages[] = $language['code']; } } else { throw new InvalidConfigException('If "navatech/yii2-multi-language" does not exists, please special "language" in config file.'); } } if ($this->enableLocaleUrls && $this->languages) { if (!$this->enablePrettyUrl) { throw new InvalidConfigException('Locale URL support requires enablePrettyUrl to be set to true.'); } } $this->_defaultLanguage = Yii::$app->language; return parent::init(); }
use navatech\role\models\Role; use navatech\role\models\RoleSearch; use yii\bootstrap\Html; use yii\data\ActiveDataProvider; use yii\grid\GridView; use yii\web\View; use yii\widgets\Pjax; /* @var $this View */ /* @var $searchModel RoleSearch */ /* @var $dataProvider ActiveDataProvider */ $this->title = Module::hasMultiLanguage() ? RoleHelper::translate('user_role') : Yii::t('role', 'User role'); $this->params['breadcrumbs'][] = $this->title; ?> <p> <?php echo Html::a(Module::hasMultiLanguage() ? RoleHelper::translate('create') : Yii::t('role', 'Create'), ['create'], ['class' => 'btn btn-success']); ?> </p> <div class="role-index"> <?php Pjax::begin(); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id', 'name', ['attribute' => 'is_backend_login', 'filter' => $searchModel->is_backend_login_array(), 'value' => function (Role $model) { $values = $model->is_backend_login_array(); return $values[$model->is_backend_login]; }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]); ?> <?php Pjax::end();
/** * @inheritdoc */ public function behaviors() { return ['verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['POST']]], 'role' => ['class' => RoleFilter::className(), 'name' => Module::hasMultiLanguage() ? RoleHelper::translate('role') : Yii::t('role', 'Role'), 'actions' => ['index' => Module::hasMultiLanguage() ? RoleHelper::translate('index') : Yii::t('role', 'List'), 'create' => Module::hasMultiLanguage() ? RoleHelper::translate('create') : Yii::t('role', 'Create'), 'update' => Module::hasMultiLanguage() ? RoleHelper::translate('update') : Yii::t('role', 'Update'), 'delete' => Module::hasMultiLanguage() ? RoleHelper::translate('delete') : Yii::t('role', 'Delete'), 'view' => Module::hasMultiLanguage() ? RoleHelper::translate('view') : Yii::t('role', 'View')]]]; }