diff --git a/src/generators/crud/Generator.php b/src/generators/crud/Generator.php index 45ba427..3166489 100644 --- a/src/generators/crud/Generator.php +++ b/src/generators/crud/Generator.php @@ -395,7 +395,8 @@ public function generate() if (is_file($templatePath.'/'.$file) && pathinfo($file, PATHINFO_EXTENSION) === 'php') { $files[] = new CodeFile("$viewPath/$file", $this->render("views/$file", [ 'model' => $model, - 'safeAttributes' => $safeAttributes + 'safeAttributes' => $safeAttributes, + 'accessDefinitions' => $accessDefinitions ])); } } diff --git a/src/generators/crud/default/access_definition.php b/src/generators/crud/default/access_definition.php index e7b10ba..2b1dcaa 100644 --- a/src/generators/crud/default/access_definition.php +++ b/src/generators/crud/default/access_definition.php @@ -13,7 +13,7 @@ /** * permissions - create name and descriptions */ -$permisions = []; +$permissions = []; foreach ($actions as $k => $action){ $name = $this->getModuleId() . '_' . $this->getControllerID() @@ -21,7 +21,7 @@ $description = $this->getModuleId() . '/' . $this->getControllerID() . '/' . $action; - $permisions[$action] = [ + $permissions[$action] = [ 'name' => $name, 'description' => $description, ]; @@ -48,6 +48,6 @@ } return [ - 'permisions' => $permisions, + 'permissions' => $permissions, 'roles' => $roles, -]; \ No newline at end of file +]; diff --git a/src/generators/crud/default/controller.php b/src/generators/crud/default/controller.php index 5b8f296..3334f9f 100644 --- a/src/generators/crud/default/controller.php +++ b/src/generators/crud/default/controller.php @@ -50,9 +50,6 @@ use yii\base\InvalidConfigException; use yii\helpers\Url; use = ltrim($generator->baseControllerClass, '\\') ?>; -accessFilter): ?> -use yii\filters\AccessControl; - use yii\web\NotFoundHttpException; use yii\web\Request; use yii\web\Response; @@ -175,7 +172,7 @@ public function actionUpdate(= $actionParams ?>) { $model = $this->findModel(= $actionParams ?>); if ($model->load($this->request->post()) && $model->save()) { - return $this->redirect(Url::previous()); + return $this->redirect(['view', = $urlParams ?>]); } return $this->render('update', ['model' => $model]); } diff --git a/src/generators/crud/default/migration_access.php b/src/generators/crud/default/migration_access.php index 3e708e8..0a841ee 100644 --- a/src/generators/crud/default/migration_access.php +++ b/src/generators/crud/default/migration_access.php @@ -13,26 +13,26 @@ class =$generator->migrationClass?> extends Migration /** * @var array controller all actions */ - public $permisions = =$generator->var_export54($accessDefinitions['permisions'],' ')?>; + public $permissions = =$generator->var_export54($accessDefinitions['permissions'],' ')?>; /** - * @var array roles and maping to actions/permisions + * @var array roles and maping to actions/permissions */ public $roles = =$generator->var_export54($accessDefinitions['roles'],' ')?>; public function up() { - $permisions = []; + $permissions = []; $auth = \Yii::$app->authManager; /** - * create permisions for each controller action + * create permissions for each controller action */ - foreach ($this->permisions as $action => $permission) { - $permisions[$action] = $auth->createPermission($permission['name']); - $permisions[$action]->description = $permission['description']; - $auth->add($permisions[$action]); + foreach ($this->permissions as $action => $permission) { + $permissions[$action] = $auth->createPermission($permission['name']); + $permissions[$action]->description = $permission['description']; + $auth->add($permissions[$action]); } /** @@ -46,7 +46,7 @@ public function up() * to role assign permissions */ foreach ($actions as $action) { - $auth->addChild($role, $permisions[$action]); + $auth->addChild($role, $permissions[$action]); } } } @@ -59,7 +59,7 @@ public function down() { $auth->remove($role); } - foreach ($this->permisions as $permission) { + foreach ($this->permissions as $permission) { $authItem = $auth->createPermission($permission['name']); $auth->remove($authItem); } diff --git a/src/generators/crud/default/views/index.php b/src/generators/crud/default/views/index.php index 659640c..de3a305 100644 --- a/src/generators/crud/default/views/index.php +++ b/src/generators/crud/default/views/index.php @@ -6,11 +6,11 @@ /** * @var yii\web\View $this * @var schmunk42\giiant\generators\crud\Generator $generator - * @var array $permisions */ $urlParams = $generator->generateUrlParams(); $nameAttribute = $generator->getNameAttribute(); +$permissions = $accessDefinitions['permissions']; /** @var \yii\db\ActiveRecord $model */ $model = new $generator->modelClass(); @@ -60,15 +60,15 @@ */ $actionColumnTemplates = []; -if (\Yii::$app->user->can('=$permisions['view']['name']?>', ['route' => true])) { +if (\Yii::$app->user->can('=$permissions['view']['name']?>', ['route' => true])) { $actionColumnTemplates[] = '{view}'; } -if (\Yii::$app->user->can('=$permisions['update']['name']?>', ['route' => true])) { +if (\Yii::$app->user->can('=$permissions['update']['name']?>', ['route' => true])) { $actionColumnTemplates[] = '{update}'; } -if (\Yii::$app->user->can('=$permisions['delete']['name']?>', ['route' => true])) { +if (\Yii::$app->user->can('=$permissions['delete']['name']?>', ['route' => true])) { $actionColumnTemplates[] = '{delete}'; } accessFilter){ echo " -if(\Yii::$app->user->can('=$permisions['create']['name']?>', ['route' => true])){ +if(\Yii::$app->user->can('=$permissions['create']['name']?>', ['route' => true])){ \n" ?> diff --git a/src/generators/crud/default/views/view.php b/src/generators/crud/default/views/view.php index 7601110..efde802 100644 --- a/src/generators/crud/default/views/view.php +++ b/src/generators/crud/default/views/view.php @@ -27,6 +27,7 @@ $className = $model::class; $modelName = Inflector::camel2words(StringHelper::basename($className)); $urlParams = $generator->generateUrlParams(); +$permissions = $accessDefinitions['permissions']; echo " @@ -60,23 +61,54 @@