注册权限十月cms
register permissions october cms
我需要有关注册插件权限的帮助。我的插件是 'event',型号是 'event'
1 如何在权限密钥中定义功能名称。
acme.blog.access_categories //I don't know how to define this feature name
2 我需要创建权限以防止某些用户在我的后端事件插件中创建事件。
我添加了新权限,但没有任何作用。
Permission I created
public function registerPermissions()
{
return [
'cng.tennis.access_events' => ['tab' => 'Events', 'label' => 'Create events']
];
}
1 Feature name
public function registerPermissions()
{
return [
'cng.tennis.access_events' => ['tab' => 'Events', 'label' => 'Create events'],
'cng.tennis.create_events' => [ ... ],
'cng.tennis.list_events' => [ ... ],
'cng.tennis.delete_events' => [ ... ],
];
}
我猜你已经添加了它'label' => 'Create events'
你可以在那里定义多个权限,这样你就可以分配每个专有名称。
对于密钥,您可以使用
2 how to use permission
To restrict whole event controller
you can add like this, now your whole controller is under that permission
<?php namespace Cng\Events\Controllers;
use Backend\Classes\BackendController;
class Events extends BackendController
{
public $requiredPermissions = ['cng.tennis.access_events'];
}
To restrict some specific features
suppose create event
you need to add restrictions manually
. for each you can add them as below
<?php namespace Cng\Events\Controllers;
use Backend\Classes\BackendController;
class Events extends BackendController
{
// other code ...
public function create($context = null) {
// checking permission manually
if (!$this->user->hasPermission(['cng.tennis.access_events'])) {
// if user do not have permission show access restricted
return \Response::make(\View::make('backend::access_denied'), 403);
}
$this->asExtension('FormController')->create($context);
}
// ...
如有疑问请评论。
我需要有关注册插件权限的帮助。我的插件是 'event',型号是 'event'
1 如何在权限密钥中定义功能名称。
acme.blog.access_categories //I don't know how to define this feature name
2 我需要创建权限以防止某些用户在我的后端事件插件中创建事件。
我添加了新权限,但没有任何作用。 Permission I created
public function registerPermissions()
{
return [
'cng.tennis.access_events' => ['tab' => 'Events', 'label' => 'Create events']
];
}
1 Feature name
public function registerPermissions()
{
return [
'cng.tennis.access_events' => ['tab' => 'Events', 'label' => 'Create events'],
'cng.tennis.create_events' => [ ... ],
'cng.tennis.list_events' => [ ... ],
'cng.tennis.delete_events' => [ ... ],
];
}
我猜你已经添加了它'label' => 'Create events'
你可以在那里定义多个权限,这样你就可以分配每个专有名称。
对于密钥,您可以使用
2 how to use permission
To restrict
whole event controller
you can add like this, now your whole controller is under that permission
<?php namespace Cng\Events\Controllers;
use Backend\Classes\BackendController;
class Events extends BackendController
{
public $requiredPermissions = ['cng.tennis.access_events'];
}
To restrict
some specific features
supposecreate event
you need to add restrictionsmanually
. for each you can add them as below
<?php namespace Cng\Events\Controllers;
use Backend\Classes\BackendController;
class Events extends BackendController
{
// other code ...
public function create($context = null) {
// checking permission manually
if (!$this->user->hasPermission(['cng.tennis.access_events'])) {
// if user do not have permission show access restricted
return \Response::make(\View::make('backend::access_denied'), 403);
}
$this->asExtension('FormController')->create($context);
}
// ...
如有疑问请评论。