【发布时间】:2014-11-07 18:33:11
【问题描述】:
下午好,
我还是 silverstripe 的新手,我正在尝试找出一些非常简单的任务。
目前,我正在尝试从我的页面控制器功能中实现安全限制,该功能已在我的 DataObject 中创建并通过 CMS 进行配置。
但是,无论我是否授予用户查看对象的权限,用户都会看到它。
请看下面的例子:
class MyComponent extends DataObject implements PermissionProvider{
///>... this is just a snippet not the full class ...
///>@Override
public function canView($member = null){
return Permission::check('COMPONENT_VIEW');
}//canView
/**
* \brief the rest of the permission functions follow the same format as above
* i.e: canEdit, canDelete, canCreate
*/
///>@Override
function providePermissions(){
return array(
'COMPONENT_VIEW' => 'Can view a component object',
'COMPONENT_EDIT' => 'Can edit a component object',
'COMPONENT_DELETE' => 'Can delete a component object',
'COMPONENT_CREATE' => 'Can create a component object',
);
}//providePermissions
}//class
好的,所以上面的课程效果很好;我可以从 CMS 管理部分为用户在组内打开|关闭权限。
这就是问题所在,请参见下面的代码:
///>Controller class snippet
class My_Controller extends Page_Controller{
public function ListMyComponents(){
$components = MyComponent::get()->filter(array('Status' => 'Enable'));
///>NOTE: How can I check to see if the user has access to view the component???
///> I've even tried, Member::canView(Member::currentUser()); It doesn't work!
return $components;
}//ListMyComponents
}//class
///>ss template file snippet
<% if ListMyComponents %>
<% loop ListMyComponents %>
$Title
<% end_loop %>
<% end_if %>
感谢您的帮助。
【问题讨论】:
标签: security controller content-management-system silverstripe