Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Once you have a permission group to reference, invoke Permissions::add() with the appropriate parameters to create your access permission, setting 'alias' as the plugin.controller class name (e.g. MyPlugin plugin FooBar controller becomes my_plugin.foo_bar) and 'action' as the method to control (use * for all methods in a controller).

Code Block
languagephp
title/plugins/my_plugin/my_plugin_plugin.php
<?php
class MyPluginPlugin extends Plugin {
 
    ...
 
    public function install($plugin_id) {
        Loader::loadModels($this, array("Permissions"));

		// Add a new permission group
        $group = array('name' => "Permission Group Name", 'level' => "staff", 'alias' => "my_plugin");
        $group_id = $this->Permissions->addGroup($group);

		// Add a new permission to the group for the FooBar controller of this plugin
        $perm = array('group_id' => $group_id, 'plugin_id' => $plugin_id, 'name' => "Some Action", 'alias' => "my_plugin.foo_bar", 'action' => "someMethod");
        $this->Permissions->add($perm);
    }
}
?>

...

Once you've added all of your access permissions there is nothing more you need to do. Your plugin will be now only be made available according to the access permissions you've defined and have been configured.

...