2008年8月3日星期日

Re: [fw-mvc] Populate drop-down list from database table

Gordon Ross-8 wrote:
>
> Is there an easy way to populate a drop-down list from a SQL table in Zend
> framework/PHP?
>

Not really, you need the data as an array to be able to use the selectbox
view helper, you can get array data directly from a Zend table model, or
create your own with the data you want. The data needs to be in id / value
pairs.

>From a table you could do a simple fetchall for the id and the value you
want. The trouble with this is I always find you want more complex options
in a select box. i.e. the ability to add a '---------Select ------' option
or a combination of field values 'Name (ID)' which doesn't work very well
with out some kind of pre processing.

So in answer no, unless you turn it all into an action helper, which is what
I've done, which means you need to write the code once!

-----
Simon

http://www.ajb007.co.uk/
--
View this message in context: http://www.nabble.com/Populate-drop-down-list-from-database-table-tp18794370p18796662.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: