为什么离子身份验证库使用自定义where()而不是使用提供的本机where()CI


    public function groups()
{
    $this->trigger_events('groups');
    // run each where that was passed
    if (isset($this->_ion_where) && !empty($this->_ion_where))
    {
        foreach ($this->_ion_where as $where)
        {
            $this->db->where($where);
        }
        $this->_ion_where = array();
    }
    if (isset($this->_ion_limit) && isset($this->_ion_offset))
    {
        $this->db->limit($this->_ion_limit, $this->_ion_offset);
        $this->_ion_limit  = NULL;
        $this->_ion_offset = NULL;
    }
    else if (isset($this->_ion_limit))
    {
        $this->db->limit($this->_ion_limit);
        $this->_ion_limit  = NULL;
    }
    // set the order
    if (isset($this->_ion_order_by) && isset($this->_ion_order))
    {
        $this->db->order_by($this->_ion_order_by, $this->_ion_order);
    }
    $this->response = $this->db->get($this->tables['groups']);
    return $this;
}

从上面的 groups(( 函数中可以看出,这对我来说似乎是无稽之谈,当 CI 已经让您选择编写本机 where((->limit((->get((,保留自己的私有_ion_limit,_ion_offset,_ion_where私有属性对工作流有任何好处时,为什么要使用自定义_ion_limit、_ion_offset_ion_where?我在这里错过了某些部分还是这里涉及一些设计模式?

在我看来

,主要原因是实现事件钩子功能。所有"重复"数据库函数都调用$this->trigger_events()而又调用提供给set_hook()的任何函数。

我有一个非常模糊的记忆,注意到其他一些体面的理由。但那是很久以前的事了,我不记得那是什么了。

最新更新