hi,

I am not sure if this is related to ZF but anyway I am asking it here.

I have a one column table (called location) in my database.

+--------------------+
|     locname     |  << this is also the primary key
+--------------------+
|  location 1      |
+--------------------+
|   location 2     |

....
and so on


In my model,  I have
==============
    public function fetchEntries()
    {
        $table = $this->getTable();
        $select = $table->select();
        return $table->fetchAll($select)->toArray();  //<<<<<  THIS IS
MY SUSPECT <<<<<

        //OR
        //return $this->getTable()->fetchAll('1')->toArray(); //<<<<<
OR THIS ONE <<<<<<
    }
==============

In my DBTables, I have
===========================
<?php

class Model_DbTable_LocationTable extends Zend_Db_Table_Abstract
{
    /** Table name */
    protected $_name    = 'location';
    protected $_primary = 'locname';

}
===========================


In my Conroller, I have
=====================
    public function indexAction()
    {
        $request = $this->getRequest();
        $form    = $this->_getTestForm();
        $modellocation = $this->_getLocationModel();
        $locations = $modellocation->fetchEntries();
        $form->getElement('adlocation')->setMultiOptions($locations);
...
...
...
=========================

In my Form, i have
========================
        $location = New Zend_Form_Element_Select('location');
        $location->setLabel('*Location:');
        $location->setRequired(true);
=========================

Everything goes fine and form renders with the Location populated but
with one problem. Array index is also shown in location listing
although it cannot be selected.

something like this:
=================

Location:
    --------------------------------
     0                               ( cannot be selected)
    --------------------------------
    Location 1                   (can be selected)
    -------------------------------
    1
    -------------------------------
    Location 2
    -------------------------------
and so on



To test this, I have created an array in my controller and tried
passing it in the form.
====================
    public function indexAction()
    {
        $request = $this->getRequest();
        $form    = $this->_getTestForm();
        $modellocation = $this->_getLocationModel();
        //$locations = $modellocation->fetchEntries();
        $locations = array( 'rat', 'cat', 'hat');
        $form->getElement('adlocation')->setMultiOptions($locations);
...
...
...
=========================

and this works fine and renders fine in the form without any index.



So that means I am really getting extra stuff when 'fetchEntries()' is
being called. Can somebody tell me what is wrong? what am I missing?

Thanks


-- 
=======================
Registered Linux User #460714
Currently Using Fedora 8, 10
=======================

Reply via email to