Php 如何在公共网站与CMS的Silverstripe中设置canView

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专门发布会员详细信息时,才能

我们在Silverstripe项目中的成员类上有一个自定义扩展:

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
  • 在CMS中,用户可以使用 管理员权限

  • 提前感谢。

    如果要在扩展中实现权限方法,可以返回:

    • true
      :授予权限
    • false
      :拒绝权限
    • null
      :不影响权限(例如,其他扩展或DataObject的基本方法将发挥作用)
    在您的情况下,返回
    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;
        }
    }