Php 如何在公共网站与CMS的Silverstripe中设置canView
我们在Silverstripe项目中的成员类上有一个自定义扩展:Php 如何在公共网站与CMS的Silverstripe中设置canView,php,silverstripe,Php,Silverstripe,我们在Silverstripe项目中的成员类上有一个自定义扩展: public function canView($member = null) { if ($this->Link() && $this->isPublished()) { return true; } else { return false; } } 因此,只有通过$This->isPublished()==true专门发布会员详细信息时,才能
public function canView($member = null) {
if ($this->Link() && $this->isPublished()) {
return true;
} else {
return false;
}
}
因此,只有通过$This->isPublished()==true
专门发布会员详细信息时,才能查看会员详细信息
该方法一直运行良好,但最近对Silverstripe 3.6.1的升级似乎破坏了它。CMS管理员不能再创建新成员(返回403/禁止错误),除非canView被覆盖为“true”:
我如何设置它以便:
$this->isPublished()==true
提前感谢。如果要在扩展中实现权限方法,可以返回:
:授予权限true
:拒绝权限false
:不影响权限(例如,其他扩展或DataObject的基本方法将发挥作用)null
false
似乎是错误的,因为如果不满足第一个条件,您将拒绝查看对象。这意味着,在这些情况下,管理员将无法在CMS中看到对象,这显然是他应该看到的
实现这一点的正确方法如下:
public function canView($member = null) {
if ($this->Link() && $this->isPublished()) {
return true;
} else {
// fall back to default permissions
return null;
}
}
public function canView($member = null) {
if ($this->Link() && $this->isPublished()) {
return true;
} else {
// fall back to default permissions
return null;
}
}