How RedFruits helps us to load data in a select?

Posted: October 15, 2010 in development
Tags: , ,

To load data in a select control you must use the object ADListModel. See the next little example:

<?php
$form = new ADForm();
...
$sel = $form->add(new ADSelectField('continents'));
$sel->setListModel(new ContinentsListModel());
...
echo $form->render();

class ContinentsListModel extends ADListModel
{
    function __construct()
    {
        $this->addValue('AF', 'Africa');
        $this->addValue('AM', 'America');
        $this->addValue('AS', 'Asia');
        $this->addValue('EU', 'Europa');
        $this->addValue('OC', 'Oceania');
    }
}
?>

There are some other ways to make this. I think the above code is more clear, but you can do this:

<?php
$form = new ADForm();
...
$sel = $form->add(new ADSelectField('continents'));
$list = new ADListModel();
$list->addValue('AF', 'Africa');
$list->addValue('AM', 'America');
$list->addValue('AS', 'Asia');
$list->addValue('EU', 'Europa');
$list->addValue('OC', 'Oceania');
$sel->setListModel($list);

echo $form->render();
?>

In this example, we are loading the data programmatically, but to get data from a data base and load them in the select control has the same difficult. RedFruits has a objects to access to data base. We’ll look later.

You can see that with RedFruits there are differents ways to solve the code needs. You only have to choose the near one to your programming needs.

That’s all!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s