【问题标题】:Adding Dummy Column in Kohana ORM在 Kohana ORM 中添加虚拟列
【发布时间】:2011-08-05 06:46:32
【问题描述】:

我想在 kohana ORM 中添加虚拟列。 我有一个 longtext 类型的字段。 我想要一个包含它的新字段 strlen。

【问题讨论】:

    标签: php kohana


    【解决方案1】:

    使用$_ignored_columns 属性:

    protected $_ignored_columns = array('text_length');
    
    public function __get($column)
    {
       if ($column == 'text_length' && (! isset($this->_object['text_length']) || isset($this->_changed['text'])))
       {
          // recalc dummy field if not set, or on long text value changing
          return $this->_object['text_length'] = strlen($this->_object['text']);
       }
    
       return parent::__get($column);
    }
    

    【讨论】:

      猜你喜欢
      • 2012-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 2011-08-06
      • 1970-01-01
      相关资源
      最近更新 更多