2016-10-13 17 views
0
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; 
} 

似乎廢話我,你可以從組看到()的原生功能上面,爲什麼使用自定義_ion_limit,_ion_offset, _ion_where當CI已經給你選擇寫本地where() - > limit() - > get()時,保留它自己的私人_ion_limit,_ion_offset,_ion_where私有屬性對工作流程有什麼好處?我是否錯過了這裏的一些部分或者是否存在某種設計模式?爲什麼離子權威性庫的使用習慣,其中()而不是使用其中()CI提供

回答

0

在我看來,主要原因是實現事件掛鉤功能。所有的「重複」數據庫函數都會調用$this->trigger_events(),然後調用提供給set_hook()的任何函數。

我有一個非常模糊的回憶,注意到一些其他體面的原因。但是,那已經過去了很長時間,我不記得那是什麼。

+0

也許是真的,似乎編寫sql語句會更靈活 – user7031

相關問題