On Sat, Jan 31, 2009 at 11:46 PM, gerardroche <[email protected]> wrote:
>
> you keep moving the goal posts.
>
> put this in your form, to the letter:
>
> $location= New Zend_Form_Element_Select('location');
> $location->setLabel('*Location:');
> $location->setMultiOptions(array('location1' => 'location1', 'location2' =>
> 'location2'));
>
>
> And in your controller:
>
> $data = array('location' => 'location1');
> $form = $this->_getTestForm();
> $form->populate($data);
>
>
> does it work? (location1 should be selected)
>
> if yes try this in controller:
>
> $data = array('location' => 'location2');
> $form = $this->_getTestForm();
> $form->populate($data);
>
> does it still work? (locations2 should now be selected in the select list)
>
> working?
>
Yes that works! and I understand what you mean about this but that is
not my question. If you read my very first post, my question was "how
to populate the select element in the form from database rows?" not
"how to select the item in the already populated select element".
that means instead of doing by hand like this
-------------------------------------------------------------------------------------------------------------------------
$location->setMultiOptions(array('location1' => 'location1',
'location2' => 'location2'));
-------------------------------------------------------------------------------------------------------------------------
I want to fill this $location automatically from database. How do I do that?
what I understood from the link you provided me is
1. I am going to manipulate the model from the form class itself (is
this true?) so that means there is no controller involved and form
have the knowledge of how to manipulate tables directly (which should
not be if we follow the MVC pattern).
But instead
1. I want to separate the datasource itself from the form.
2. What I wanted to do is Controller will be responsible for fetching
the data from the model and pass an array to the form. Form have no
knowledge of how that data arrives there but knows that something have
been provided by controller for it to manipulate. So in my case
controller provides the location array to form and form will populate
the Zend_Form_Element_Select before showing it.
3. The part I wanted to know is how this mechanism works (or how to
make that happen)?
That's why I asked in my first post:
a) Do I need to declare global variable in my form class plus getter,
setter methods so that Controller can set that variable through those
methods and I can use the data provided in that variable?
b) or when controller uses $form->populate(some array), the form
already have knowledge of what's being passed to it? If so how the
form will knows what to reference?
If I understand this then I know what I am looking for and can figure
out how to write the code I need.
Please correct me if I am wrong about my concept.
Now can you explain how this works and how to make that happen in
plain English (no code involved)
Thanks
--
=======================
Registered Linux User #460714
Currently Using Fedora 8, 10
=======================