大家好:
我有一系列model 因為欄位統一 所以都這樣寫
class Product extends AppModel {
function __construct() {
parent:GDN__construct();
$this->displayField = 'title_lang1';
$this->name = get_class($this);
$this->order = "{$this->name}.show_index DESC";
}
}
這樣每一個Model都可以標準化一點,貼同一段程式在不同的model就可以定義一些統一的資料
可是最近有一個需求是要做無限層的資料結構
所以參考了手冊 3.7.6.8 Multiple relations to the same model
http://book.cakephp.org/1.3/view/1046/Multiple-relations-to-the-same-model
發現hasMany 和belongsTo 都可以指定自已model
不過發現同時寫了__construct() 加 指定自已model這邊就會出現錯誤訊息:
Fatal error: Maximum function nesting level of '100' reached, aborting!
雖然model的displayField 和order屬性還是可以乖乖一個一個寫
可是還是想請教大家,有什麼可以少做這些多維護的工作呢?
謝謝^^
原始討論:
http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=6557
評論
可是這段程式寫到app_model.php 也是會造成nesting level of '100'的錯訊
應該是hasMany 自已model時 自已撈自已又叫自已的建構子> < 成了無限迴圈
不過cake裡面撈資料的好處就不見了耶
比如說 撈訂單,自動帶出對應訂單明細
> <