Re: DB_DataObject FormBuilder
| From: | Justin Patrin | Date: | Tue, 09 Mar 2004 17:36:30 +0000 |
| Subject: | Re: DB_DataObject FormBuilder | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-11184@lists.php.net to get a copy of this message | ||
Markus Wolff wrote:
David Thunman wrote:I added some functionality for displaying multiple fields in a select a little while ago. If you make a db.formBuilder.ini file (where db is the name of the DB) and put soemthing like this in there: [tableName__display_fields] 0 = firstName 1 = lastName You can put as many fields as you want in there. If one of them is a foreign key (link), it will look up the display fields of the connected row as well. :-) Oh, you have to add this to your DataObject.ini also: [DB_DataObject_FormBuilder] follow_links = 2 You can make that any number you want, it defines the maximum recursive link level. 2 is probably fine for any normal use. -- paperCrane <Justin Patrin>Now I bumped in to a problem creating select menu items where I want the label text of an option to be built up from two different cell values in the related table. In my case they are "tablename.last_name" and "tablename.first_name" ehich I#d like to concatenate into one string. By default, I think, the formbuilder class uses the first collumn after the primary key from the related table to create the option label text(?).Nope, you can define which field will be used to render the entry by either putting this into your dataobject.ini: [DB_DataObject_FormBuilder] select_display_field = Description ...or, you can override this setting by defining a similarly-named property in the class that represents the table you want to display: var $select_display_field = "Some_Other_Description";Is there an easy way to define this in an ini file or do I have to hack the formbuilder.class file to for this?Currently, there is no way to do this without some tweaking. In the rare occasions I need something like this, I just use the preGenerateForm() method and simply define the selectbox element as I please before FormBuilder takes action. You do it in the class from which you want to build the form: function preGenerateForm(&$fb) {$options = array(); $related = DB_DataObject::factory('DataObject_RelatedTable'); $related->query('SELECT id, CONCAT(fieldOne,fieldTwo) AS field'); while ($related->fetch()) { $options[$related->id] = $related->field; } unset($related); $box = HTML_QuickForm::createElement('select','related_id', 'My related Table, $options); $this->preDefElements['related_id'] = $box;} To automate things like this in the future, it might be nice to add another optional property with which you can define an SQL snippet which is used for getting the field when displaying it in a selectbox... or does anyone have a better idea? CU Markus