Re: unclear understanding formBuilder getSelectOptions
| From: | Sarah Gray | Date: | Thu, 03 Jun 2004 22:09:33 +0000 |
| Subject: | Re: unclear understanding formBuilder getSelectOptions | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-12881@lists.php.net to get a copy of this message | ||
Thank you so much Markus! That did the trick.
s.
Markus Wolff wrote:
> Sarah Gray wrote:
>
> > I'm having usage problems (ie, lack of understanding) of how to
> > successfully use
> > getSelectOptions in FormBuilder. Perhaps I misunderstand the function
> > itself? I think
> > it is to display text options when you have a dropdown menu composed of
> > options
> > from a linked table.
> >
> > I have a form with a link to another table, the link is being read by
> > the morchand.links.ini file
> [...]
> > I tried setting this in the morchand.links.ini file but was just
> > guessing at semantics
> > and I'm not clear how to set the ini file so that "For the display name
> > of the option, it will try to use the settings in the
> > database.formBuilder.ini file" --
> > since my app has many tables and not just one set_display_field.
>
> Hi Sarah,
>
> normally, you won't need to use getSelectOptions() yourself - if it's
> called from outside FormBuilder, this usually is because you want to add
> some additional options manually to the generated list.
>
> If you are in a situation where many of your tables have different field
> names which should be used for populating selectboxes, just don't use
> the select_display_field option in the .ini file, but but a similarly
> named property into the dataobject that you want to display.
>
> Say, you generate a form from DataObject_A. DataObject_A has a link to
> DataObject_B, so a selectbox is created from the records found in
> DataObject_B.
> In case you have defined the option select_display_field globally in
> your .ini file, FormBuilder will try to find the defined field in
> DataObject_B to display the values in the selectbox. In your situation,
> however, you would put it as a new property into DataObject_B:
>
> class DataObject_B
> {
> ### Autogenerated code...
> var $id; // Primary Key
> var $displayMePlease; // Field to be displayed in selectboxes
> ### End autogenerated code...
>
> // Your new property:
> var $select_display_field = 'displayMePlease';
> }
>
> Whenever DataObject_B is being used to populate a selectbox, the field
> "displayMePlease" will now be used to, well, display the records ;-)
>
> Even if you should have set select_display_field globally in your .ini
> file, setting it again as a property in your dataobjects will always
> override the global value. This way, you can define the most commonly
> used field name globally and only need to add something to those classes
> where the field name differs.
>
> I hope I was able to make this a bit clearer.
>
> CU
> Markus