Re: Re: FormBuilder and QuickForm_Controller

From: Date: Wed, 09 Mar 2005 10:00:44 +0000
Subject: Re: Re: FormBuilder and QuickForm_Controller
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17933@lists.php.net to get a copy of this message
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dear Justin, Thanks for getting back to me so rapidly. I have spent a morning "fiddling"... > Well, it does work for me. ;-) Doubtless ;-) > You should have opened a bug report if the newer versions broke your > scripts. Oh well, we'll try to fix it now. Apathy rules! Well, it would if it could be bothered! I'm new to PHP and Pear, I was initilaly scouting around for components to build a DB app, so was really looking for stuff that works out of the box. Of course now I quite like the idea behind DO and FormBuilder. While it's not necessarilly a good idea to commit oneself to something which is "Beta" it's fun.... ! > The problem is probably with _getPrimaryKey(). Please look into this > function and see if you can find any reason it doesn't work with your > DOs. It *looks* like one of these calls is returning '', an empty > string (perhaps sequenceKey()?). Perhaps this is a DO issue? One thing I noticed was the sequences generated by the DO when using (say) ->insert() are not the same as using the raw SQL. This is worrying, i.e. while ->insert() always increments SERIAL keys and so does the SQL INSERT, they do so independently! This means one can clash with the other. I have just made a decision to only use ->insert() methods. However this is not ideal in the long term. Do you think this could be related to the _primary_key issue? > I'd appreciate it if you could make the appropriate DO and send back > the output of this: Done below. N.B. In case it matters, am using PostgreSQL 7.4.7 and PHP 4.3.10. SQL commands to build an example table. CREATE TABLE test ( index SERIAL, name VARCHAR(512), note VARCHAR(1024), PRIMARY KEY (index) ); Resulting DO generated by createTables.php <?php /** * Table Definition for paperstatus */ require_once 'DB/DataObject.php'; class DataObjects_Test extends DB_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ var $__table = 'test'; // table name var $index; // int4(4) not_null default_nextval%28public.test_index_seq%29 primary_key var $name; // varchar(-1) var $note; // varchar(-1) /* ZE2 compatibility trick*/ function __clone() { return $this;} /* Static get */ function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Test',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE } Note, the DB_DATAOBJECT_NO_OVERLOAD which is required for PHP 4. x, mentioned here in case it's a problem. // ******************** Test script ************************* <?php define('DB_DATAOBJECT_NO_OVERLOAD',true); require_once('DB/DataObject.php'); // If so then do all the configuration for the Data Objects and FormBuilder require_once('PEAR.php'); $options = &PEAR::getStaticProperty('DB_DataObject','options'); $config = parse_ini_file('/var/www/php/OJ/DataObjects/DataObjects.ini',TRUE); $options = $config['DB_DataObject']; require_once('DB/DataObject/FormBuilder.php'); $do = DB_DataObject::factory('test'); echo "<pre>"; echo ' PK '; var_dump($do->_primary_key); echo ' SK '; var_dump($do->sequenceKey()); echo ' K '; var_dump($do->keys()); echo "</pre>"; ?> /********* RESULT *********************/ PK Notice: Undefined property: _primary_key in /var/www/html/test.php on line 15 NULL SK array(3) { [0]=> string(5) "index" [1]=> bool(false) [2]=> bool(false) } K array(1) { [0]=> string(5) "index" } > Then try changing the _getPrimaryKey function in FormBuilder.php to > this and see if it works: > > function _getPrimaryKey(&$do) { > if (isset($do->_primary_key) && strlen($do->_primary_key)) { > return $do->_primary_key; > } elseif (($seq = $do->sequenceKey()) && isset($seq[0]) && > strlen($seq[0])) { > return $seq[0]; > } else { > if (($keys = $do->keys()) && isset($keys[0]) && > strlen($keys[0])) { return $keys[0]; > } > } > $this->debug('Error: Primary Key not found for table > '.$do->tableName()); > return false; > } Almost does.. Now when using it on tables which have links I get: Notice: Undefined index: database in /usr/share/pear/DB/DataObject/FormBuilder/QuickForm/PopupSelect.php on line 103 Other version info DB 1.7.2 stable DB_DataObject 1.7.7 stable DB_DataObject_FormBuilder 0.12.1 beta HTML_QuickForm 3.2.4pl1 stable So, I'm happy to try things, where too now? Cheers, - -ed -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFCLslM+i4TdNhCMrYRAuH6AKDgQbkmRug/QKBZ+g+1fGu2IYE/BQCeI++n aXMtFNrYAdxG5e+1ENi6yZU= =a1Bx -----END PGP SIGNATURE-----

« previous php.pear.general (#17933) next »