【问题标题】:Extending Sentry 2 Models from a Base Eloquent class从基本 Eloquent 类扩展 Sentry 2 模型
【发布时间】:2013-09-04 02:35:55
【问题描述】:

目前我的所有模型都扩展了一个名为 "Base"

的基类

Base 扩展 Eloquent

问题是我使用 Sentry 2 进行用户身份验证和组,因此我的两个模型 UserGroup 扩展了它们各自的 Sentry 基本模型 SentryUserModelSentryGroupModel

我想不出一种方法来拥有这两个模型:User, Group 扩展了我的 Base 模型

【问题讨论】:

    标签: php oop inheritance laravel-4 eloquent


    【解决方案1】:

    您可以让您的 User 和 Group 模型分别扩展 SentryUserModel 和 SentryGroupModel,然后使用魔法函数扩展 Base 模型。

    代码:

    class User extends SentryUserModel
    {
          private $base;
    
          function __construct()
          {
              $this->base = new Base();
          }
    
          // fake "extends Base" using magic function
          public function __call($method, $args)
          {
              $this->base->$method($args[0]);
          }        
    }
    
    
    class Group extends SentryGroupModel
    {
          private $base;
    
          function __construct()
          {
              $this->base = new Base();
          }
    
          // fake "extends Base" using magic function
          public function __call($method, $args)
          {
              $this->base->$method($args[0]);
          }        
    }
    

    【讨论】:

      猜你喜欢
      • 2014-02-24
      • 1970-01-01
      • 2020-06-19
      • 2015-07-14
      • 2021-07-21
      • 1970-01-01
      • 1970-01-01
      • 2012-05-08
      • 1970-01-01
      相关资源
      最近更新 更多