Re: Framework Development (2)

From: Date: Sat, 15 Jun 2002 18:38:35 +0000
Subject: Re: Framework Development (2)
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-7054@lists.php.net to get a copy of this message
Hi, I was looking for something like that. I have a framework I use in my consulting that is a RAD framework based in phplib+some classes of mine. One of those do exactly the same role as yours KBBObj. I spent my little spare time looking to put those classes in a MVC like framework. That someday will allow me to get the PHP code from a XML schema. By now i found some Pear packages that will play a role on that dream: HTML_OOH_Form (Not pearified yet and I dont really studied the wizard part too, i guess i would be better have those controls in a Control class apart of the forms) MDB of course... and the missing part(not more) a DB Obj to handle data from the forms to the DB. Is the AK DBoo pearified? I really liked the class you sent. Mainly the idea of allowedfields. That sounds very nice with a ACL class (that we dont have, if i understand the last Pear::Auth discussion). Thinking...., it shouldnt be better have a forbidenFields array instead? I thing in most cases we can default to empty forbiddenFields and bypass some code. And I going to play with your class right now :) Sebastiao Rocha. > Simon Biela <s.biela@kernpunkt.de> wrote*: > > As I realised that sending attachments is not very intelligent, here's > the code of the class: As I realised that sending attachments is not > very intelligent, here's the code of the class: > <? > class KBDBObject > { > var $table; > var $fields; > var $keycolumn; > var $db; > var $allowedfields; > > // sets key-value > function setKeyColumn($_name) > { > $this->keycolumn = $_name; > } > > // sets the table-name in the database > function setTable($_name) > { > $this->table = $_name; > } > > // Contructor setting the fields allowed (field in the database) and > the db name // and maybe calling read_from_database() if id is given. > function KBDBObject($_db, $id) > { > $this->db = $_db; > $this->allowedfields = ''; > //$this->allowedfields = array(); > //array_push($this->allowedfields, 'password'); > } > > > function setFields($_fields) > { > foreach ($_fields as $key => $value) > { > $this->setField($key, $value); > } > } > > > function setField($_name, $_value) > { > if ($this->allowedfields != '') > { > if (in_array($_name, $this->allowedfields)) > { > $this->fields[$_name] = $_value; > } > else > { > trigger_error("Invalid field added", E_USER_WARNING); > } > } > else > $this->fields[$_name] = $_value; > } > > > function unsetField($_name) > { > unset($this->fields[$_name]); > } > > // get fields from the database > function get_fields() { > } > > function get_field() { > } > > // save the object in the database > // will basically call the update or insert function > function write_to_database() { > } > > // read an object from the database > // will call the select() function > function read_from_database() { > } > > // building the sql for insert and sending to adodb > function insert() > { > $sqlst = "INSERT INTO ".$this->table." ("; > > foreach ($this->fields AS $key => $value) > { > if ($key != $this->keycolumn) > { > if ($this->allowedfields != '') > { > if (in_array($key, $this- >allowedfields)) > { > $sqlst .= $key.', '; > } > } > else > $sqlst .= $key.', '; > } > } > $sqlst = substr($sqlst, 0, (strlen($sqlst) - 2)).') VALUES ('; > foreach ($this->fields AS $key => $value) > { > if ($key != $this->keycolumn) > { > if ($this->allowedfields != '') > { > if (in_array($key, $this- >allowedfields)) > { > $sqlst .= "'".$value."', "; > } > } > else > $sqlst .= "'".$value."', "; > } > } > $sqlst = substr($sqlst, 0, (strlen($sqlst) - 2)).')'; > > echo $sqlst.'<br>'; > /* > if ($this->db->Execute($sql) === false) > { > print 'error inserting: '.$conn->ErrorMsg ().'<BR>'; > } > */ > } > > // building the sql for update and sending to adodb > function update($keyvalue) > { > $sqlst = "UPDATE ".$this->table." SET "; > > foreach ($this->fields AS $key => $value) > { > if ($key != $this->keycolumn) > { > if ($this->allowedfields != '') > { > if (in_array($key, $this- >allowedfields)) > { > $sqlst .= $key." = '".$value."'".', '; > } > } > else > $sqlst .= $key." = '".$value."'".', '; > } > } > $sqlst = substr($sqlst, 0, (strlen($sqlst) - 2)).' WHERE > '.$this->keycolumn." = '".$keyvalue."'"; > > echo $sqlst.'<br>'; > } > > // building the sql for delete and sending to adodb > function delete($keyvalue) > { > $sqlst = "DELETE FROM ".$this->table." WHERE ".$this->keycolumn." = > '".$keyvalue."'"; > > echo $sqlst.'<br>'; > } > > // building the select sql and sending to adodb > function select() { > } > > } > ?> > > > > mit freundlichen Gruessen > > Simon Biela > Geschaeftsfuehrung > > --- > kernpunkt GmbH > cross communication > Krefelder Strasse 18 > 50670 Koeln > > tel: +49 221 - 569 576 10 > fax: +49 221 - 569 576 29 > infoline: 0800 KERNPUNKT > >s.biela@kernpunkt.de > http://www.kernpunkt.de > > -- > PEAR Development Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.pear.dev (#7054) next »