我正在瀏覽SO,並發現這個託管代碼作爲削減PHP代碼的推薦方式。Codeigniter:不知道如何撥打這段代碼
https://github.com/jamierumbelow/codeigniter-base-model
到目前爲止,從我想通了如何使用方法,我喜歡它做什麼,以及如何簡單,它使事情。
然而,在下面的代碼:
/**
* Get a single record by creating a WHERE clause by passing
* through a CI AR where() call
*
* @param string $key The key to search by
* @param string $val The value of that key
* @return object
*/
public function get_by() {
$where =& func_get_args();
$this->_set_where($where);
$this->_run_before_get();
$row = $this->db->get($this->_table)
->row();
$this->_run_after_get($row);
return $row;
}
我不完全知道如何對這個函數的調用。 它所做的描述正是我想要做的。
@params表示它需要WHERE塊的鍵和值對,但在方法簽名中沒有看到任何函數輸入。
請幫忙嗎?
你想使用整個類或只是該方法? –
我正在嘗試使用這個類。他有很好的指導,所以我能夠毫無問題地「安裝」課程。我可以對其他方法進行函數調用。不知道如何去調用這個方法,因爲我沒有看到任何示例代碼。 – Zigu
方法成爲你的模型的一部分,只能從你自己的方法調用這些方法:'$ query = $ this-> get_by($ key,$ val);'然後'$ query-> fied;' –