Something like this would be shorter I think:
in your model:
$rows = $this->_db->fetchPairs(
$this->select()->from($this->_name, array('id', 'label')) );
if (!$rows) {
throw new Exception("Could not find rows");
}
return $rows;
then you can pass the function to your form select element.
scs
On Sat, Dec 5, 2009 at 1:33 AM, Mark Steudel <[email protected]> wrote:
> I want to pass a zend_form_select with contents from a table. Right
> now I'm doing something like
>
> public function retrieveDistrictsForSelect() {
> $select = $this->select()->from( 'districts' );
> $select->order( 'school_district_name' );
>
> $stm = $select->query();
> $rows = $stm->fetchAll();
>
> if( is_array( $rows ) && count( $rows ) > 0 ) {
> foreach( $rows as $row ) {
> $district[$row['id']] =
> $row['school_district_name'];
> }
> }
>
> return $district;
> }
>
> Then passing it into the setMultiOptions of the select element. I was
> wondering if there was some better way to pass in Db_Table object?
>
> MS
>