john.brown Posted November 26, 2006 Report Share Posted November 26, 2006 Ir man divas klasītes class model_NewsList { var $db = NULL; var $news = NULL; function model_NewsList() { $dbfile = NEWS_PATH.'/data.dat'; $this->db = & MICROdb::instance(); if(!is_file($dbfile)) { $this->db->createTable($dbfile,array('title','body','time')); } else $this->db->connectDB($dbfile,2); $this->news = $this->db->selectWhere('*'); } function get() { if(list($id,$vals) = each($this->news)) { // šeit ir problēma $news = new model_News($this); // ja nepadod $this tad viss iet $news->fill($vals); return $news; } return false; } .... } class model_News { var $id = NULL; var $title = NULL; var $body = NULL; var $time = NULL; var $list = NULL; function model_News(&$list) { $this->list = $list; } function fill($data) { foreach($data as $key => $value) { $this->$key = $value; } } function save() { $this->list->save($this); } function del() { $this->list->del($this); } function setId($id) { $this->id = $id; } } Joki tādi, ka each() vienmēr atgriež tik pirmo masīva elementu. Ja nepadod referenci uz NewsList, viss notiek pareizi. Nekādi nesaprotu, kas par fišku - it kā tak tā reference nekur neiesaistās pie masīva apiešanas... Link to comment Share on other sites More sharing options...
bubu Posted November 26, 2006 Report Share Posted November 26, 2006 Tu gadījumā starp get() izsaukumiem neizmaini $news masīvu? Link to comment Share on other sites More sharing options...
john.brown Posted November 26, 2006 Author Report Share Posted November 26, 2006 (edited) Nē, nekas netiek mainīts $newsList = new model_NewsList(); while($news = $newsList->get()) { include(TPL_PATH.'/newstpl.php'); } Tas jau ar ir dīvaini. Principā jau problēmu apgāju - uzrakstīju savu each() analogu, tak tīri teorētiski... Vispār jau php4 priekš oop ir sucks :( P.S. uz php5 viss tas pats iet kā pa sviestu :) Edited November 26, 2006 by john.brown Link to comment Share on other sites More sharing options...
Recommended Posts